-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
90 lines (66 loc) · 1.97 KB
/
main.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
provider "aws" {
region = "${var.aws_region}"
}
resource "aws_cloudwatch_event_rule" "check-file-event" {
name = "check-file-event"
description = "check-file-event"
schedule_expression = "cron(0 1 ? * * *)"
}
resource "aws_cloudwatch_event_target" "check-file-event-lambda-target" {
target_id = "check-file-event-lambda-target"
rule = "${aws_cloudwatch_event_rule.check-file-event.name}"
arn = "${aws_lambda_function.check_file_lambda.arn}"
}
resource "aws_iam_role" "check_file_lambda" {
name = "check_file_lambda"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
data "aws_iam_policy_document" "s3-access-ro" {
statement {
actions = [
"s3:*",
]
resources = [
"arn:aws:s3:::*",
]
}
}
resource "aws_iam_policy" "s3-access-ro" {
name = "s3-access-ro"
path = "/"
policy = "${data.aws_iam_policy_document.s3-access-ro.json}"
}
resource "aws_iam_role_policy_attachment" "s3-access-ro" {
role = "${aws_iam_role.check_file_lambda.name}"
policy_arn = "${aws_iam_policy.s3-access-ro.arn}"
}
resource "aws_lambda_permission" "allow_cloudwatch_to_call_check_file" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = "${aws_lambda_function.check_file_lambda.function_name}"
principal = "events.amazonaws.com"
source_arn = "${aws_cloudwatch_event_rule.check-file-event.arn}"
}
resource "aws_lambda_function" "check_file_lambda" {
filename = "check_file_lambda.zip"
function_name = "check_file_lambda"
role = "${aws_iam_role.check_file_lambda.arn}"
handler = "check_file_lambda.handler"
runtime = "python3.6"
timeout = 300
source_code_hash = "${filebase64sha256("check_file_lambda.zip")}"
}