-
Notifications
You must be signed in to change notification settings - Fork 4
/
lambda.tf
69 lines (55 loc) · 1.76 KB
/
lambda.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
resource "aws_lambda_function" "test_lambda" {
# If the file is not in the current working directory you will need to include a
# path.module in the filename.
depends_on = [
aws_iam_role_policy_attachment.test-attach
]
filename = "${data.archive_file.my_lambda_function.output_path}"
function_name = "lambda_function"
role = aws_iam_role.lambda_sqs_role.arn
handler = "lambda_function.lambda_handler"
timeout = 6
# The filebase64sha256() function is available in Terraform 0.11.12 and later
# For Terraform 0.11.11 and earlier, use the base64sha256() function and the file() function:
# source_code_hash = "${base64sha256(file("lambda_function_payload.zip"))}"
source_code_hash = "${data.archive_file.my_lambda_function.output_base64sha256}"
runtime = "python3.9"
environment {
variables = {
REGION = "${var.aws_region}"
}
}
}
data "archive_file" "my_lambda_function" {
type = "zip"
output_path = "my_lambda_function.zip"
source_file = "lambda_function.py"
}
resource "aws_iam_role" "lambda_sqs_role" {
name = "lambda_sqs_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "lambda.amazonaws.com"
}
},
]
})
tags = {
key = "name"
value = "lambda_sqs_role"
}
}
resource "aws_iam_role_policy_attachment" "test-attach" {
role = aws_iam_role.lambda_sqs_role.name
count = length(var.iam_policy_arn)
policy_arn = var.iam_policy_arn[count.index]
depends_on = [
aws_iam_role.lambda_sqs_role
]
}