-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcloudwatch.tf
36 lines (34 loc) · 899 Bytes
/
cloudwatch.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
resource "aws_cloudwatch_event_rule" "putImage" {
name = "capture-ecr-put-image"
description = "Capture Each ECR Put Image Operation"
event_pattern = <<PATTERN
{
"source": [
"aws.ecr"
],
"detail-type": [
"AWS API Call via CloudTrail"
],
"detail": {
"eventSource": [
"ecr.amazonaws.com"
],
"eventName": [
"PutImage"
]
}
}
PATTERN
}
resource "aws_cloudwatch_event_target" "lambda" {
rule = "${aws_cloudwatch_event_rule.putImage.name}"
target_id = "ecrPutImage"
arn = "${aws_lambda_function.imageScanner.arn}"
}
resource "aws_lambda_permission" "allow_cloudwatch" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = "${aws_lambda_function.imageScanner.arn}"
principal = "events.amazonaws.com"
source_arn = "${aws_cloudwatch_event_rule.putImage.arn}"
}