-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlambda.tf
76 lines (70 loc) · 1.79 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
70
71
72
73
74
75
76
resource "aws_iam_role" "demo" {
name = "iam_for_lambda_demo"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
# This policy need to run Lambda in VPC
#
resource "aws_iam_role_policy" "demo" {
name = "lambda-demo"
role = "${aws_iam_role.demo.id}"
policy = <<EOF
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"AllowCreationOfLogGroupsAndStreams",
"Effect":"Allow",
"Action":[
"logs:CreateLogGroup",
"logs:CreateLogStream"
],
"Resource":"arn:aws:logs:*:*:*"
},
{
"Sid":"AllowLogging",
"Effect":"Allow",
"Action":"logs:PutLogEvents",
"Resource":"arn:aws:logs:*:*:log-group:/aws/lambda/*:*"
},
{
"Sid":"AllowEniMgmtForVpcAccess",
"Effect":"Allow",
"Action":[
"ec2:CreateNetworkInterface",
"ec2:DescribeNetworkInterfaces",
"ec2:DeleteNetworkInterface"
],
"Resource":"*"
}
]
}
EOF
}
resource "aws_lambda_function" "demo" {
depends_on = ["null_resource.demo", "aws_rds_cluster.demo", "aws_rds_cluster_instance.demo"]
filename = "../lambda/lambda-demo.zip"
function_name = "lambda-demo"
runtime = "python2.7"
timeout = 30
role = "${aws_iam_role.demo.arn}"
handler = "lambda-demo.handler"
source_code_hash = "${base64sha256(file("../lambda/lambda-demo.zip"))}"
vpc_config {
subnet_ids = ["${aws_subnet.demo.*.id}"]
security_group_ids = ["${aws_security_group.demo.id}"]
}
}