-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda-task.tf
69 lines (62 loc) · 1.63 KB
/
lambda-task.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_iam_role" "lambda-task-role" {
name = "lambda-task-role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_role_policy" "lambda-task-policy" {
name = "lambda-task-policy"
role = "${aws_iam_role.lambda-task-role.id}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:*",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"${aws_dynamodb_table.tasks-dynamodb-table.arn}",
"arn:aws:logs:*:*:*"
]
}
]
}
EOF
}
resource "aws_cloudwatch_log_group" "lambda-task-loggroup" {
name = "/aws/lambda/lambda-task"
retention_in_days = 7
}
resource "aws_lambda_function" "lambda-task" {
filename = "lambda-task.zip"
function_name = "lambda-task"
role = "${aws_iam_role.lambda-task-role.arn}"
handler = "main"
# 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 = "${filebase64sha256("lambda-task.zip")}"
runtime = "go1.x"
environment {
variables = {
dynamo_table = "${aws_dynamodb_table.tasks-dynamodb-table.name}"
region = "${data.aws_region.current.name}"
}
}
}