-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda.tf
More file actions
47 lines (41 loc) · 1.5 KB
/
lambda.tf
File metadata and controls
47 lines (41 loc) · 1.5 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
resource "aws_lambda_function" "test_lambda" {
filename = "function.zip"
function_name = "lambda_trigger"
role = "${aws_iam_role.test_role.arn}"
handler = "main.lambda_handler"
# 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("function.zip")}"
runtime = "python3.7"
}
resource "aws_cloudwatch_event_rule" "CWRule" {
name = "CWRule"
event_pattern = <<PATTERN
{
"source": [
"aws.autoscaling"
],
"detail-type": [
"EC2 Instance Launch Successful",
"EC2 Instance Terminate Successful",
"EC2 Instance Launch Unsuccessful",
"EC2 Instance Terminate Unsuccessful",
"EC2 Instance-launch Lifecycle Action",
"EC2 Instance-terminate Lifecycle Action"
]
}
PATTERN
}
resource "aws_cloudwatch_event_target" "ansible" {
rule = "${aws_cloudwatch_event_rule.CWRule.name}"
target_id = "Ansible"
arn = "arn:aws:lambda:eu-central-1:998069768433:function:lambda_trigger"
}
resource "aws_lambda_permission" "allow_cloudwatch_to_call" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = "${aws_lambda_function.test_lambda.function_name}"
principal = "events.amazonaws.com"
source_arn = "${aws_cloudwatch_event_rule.CWRule.arn}"
}