-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlambda-test_page_list.tf
146 lines (127 loc) · 3.32 KB
/
lambda-test_page_list.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
resource "aws_iam_role" "test_page_list" {
name = "test-page-list"
path = "/service-role/"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": [
"lambda.amazonaws.com",
"edgelambda.amazonaws.com"
]
},
"Effect": "Allow"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "test_page_list" {
role = aws_iam_role.test_page_list.name
policy_arn = data.aws_iam_policy.AWSLambdaBasicExecutionRole.arn
}
resource "aws_iam_role_policy" "test_page_list" {
name = "test-bucket-access"
role = aws_iam_role.test_page_list.id
# Terraform's "jsonencode" function converts a
# Terraform expression result to valid JSON syntax.
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"s3:ListAllMyBuckets",
]
Effect = "Allow"
Resource = "*"
},
{
Action = [
"s3:GetObject",
"s3:ListBucket",
]
Effect = "Allow"
Resource = [
"arn:aws:s3:::test.${var.common_domain}/*",
"arn:aws:s3:::test.${var.common_domain}"
]
},
]
})
}
resource "aws_iam_policy" "test_page_list_dynamodb_access" {
name = "DynamoDBAccess"
path = "/"
# description = "My test policy"
# Terraform's "jsonencode" function converts a
# Terraform expression result to valid JSON syntax.
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "dynamodb:ListTables"
Effect = "Allow"
Resource = "*"
},
{
Action = [
"dynamodb:DescribeTable",
"dynamodb:GetItem",
"dynamodb:Scan",
"dynamodb:Query"
]
Effect = "Allow"
Resource = [
"arn:aws:dynamodb:*:${data.aws_caller_identity.current.account_id}:table/test-page-list/index/*",
"arn:aws:dynamodb:*:${data.aws_caller_identity.current.account_id}:table/test-page-list"
]
},
]
})
}
resource "aws_iam_role_policy_attachment" "test_page_list_dynamodb_access" {
role = aws_iam_role.test_page_list.name
policy_arn = aws_iam_policy.test_page_list_dynamodb_access.arn
}
data "archive_file" "test_page_list" {
type = "zip"
source_dir = "${path.module}/src_code/test-page-list"
output_file_mode = "0666"
output_path = "${path.module}/local_output/test-page-list.zip"
}
resource "aws_lambda_function" "test_page_list" {
provider = aws.us-east-1
filename = data.archive_file.test_page_list.output_path
function_name = "test-page-list"
role = aws_iam_role.test_page_list.arn
handler = "lambda_function.lambda_handler"
publish = true
source_code_hash = filebase64sha256(data.archive_file.test_page_list.output_path)
runtime = "python3.12"
timeout = 5
tags = {
Terraform = true
}
}
resource "aws_dynamodb_table" "test_page_list" {
provider = aws.us-east-1
name = "test-page-list"
billing_mode = "PROVISIONED"
read_capacity = 5
write_capacity = 5
hash_key = "gitHash"
attribute {
name = "gitHash"
type = "S"
}
ttl {
attribute_name = "expirationTime"
enabled = true
}
tags = {
Terraform = true
}
}