-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlambda-image_submission_handler.tf
More file actions
95 lines (84 loc) · 2.35 KB
/
lambda-image_submission_handler.tf
File metadata and controls
95 lines (84 loc) · 2.35 KB
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
resource "aws_iam_role" "image_submission_handler" {
name = "image-submission-handler"
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
}
data "aws_iam_policy" "AWSLambdaBasicExecutionRole" {
path_prefix = "/service-role/"
name = "AWSLambdaBasicExecutionRole"
}
resource "aws_iam_role_policy_attachment" "image_submission_handler" {
role = aws_iam_role.image_submission_handler.name
policy_arn = data.aws_iam_policy.AWSLambdaBasicExecutionRole.arn
}
resource "aws_iam_role_policy" "image_submission_handler" {
name = "bucket_access"
role = aws_iam_role.image_submission_handler.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:PutObject",
"s3:GetObjectAcl",
"s3:GetObject",
"s3:ListBucketMultipartUploads",
"s3:AbortMultipartUpload",
"s3:ListBucket",
"s3:DeleteObject",
"s3:GetBucketLocation",
"s3:ListMultipartUploadParts",
]
Effect = "Allow"
Resource = [
aws_s3_bucket.images.arn,
"${aws_s3_bucket.images.arn}/*"
]
},
]
})
}
data "archive_file" "image_submission_handler" {
type = "zip"
source_dir = "${path.module}/src_code/image-submission-handler"
output_file_mode = "0666"
output_path = "${path.module}/local_output/image-submission-handler.zip"
}
resource "aws_lambda_function" "image_submission_handler" {
provider = aws.us-east-1
filename = data.archive_file.image_submission_handler.output_path
function_name = "image-submission-handler"
role = aws_iam_role.image_submission_handler.arn
handler = "index.handler"
publish = true
source_code_hash = filebase64sha256(data.archive_file.image_submission_handler.output_path)
runtime = "nodejs20.x"
tags = {
Terraform = true
}
}