forked from UKHomeOffice/acp-tf-lambda-es-reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule.tf
23 lines (20 loc) · 827 Bytes
/
schedule.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
locals {
schedule_expression = "rate(${var.period_minutes} minutes)"
}
resource "aws_cloudwatch_event_rule" "schedule" {
name = "${var.function_name}-schedule"
description = "${var.function_name} trigger schedule"
schedule_expression = local.schedule_expression
}
resource "aws_cloudwatch_event_target" "lambda_target" {
rule = aws_cloudwatch_event_rule.schedule.name
target_id = "${var.function_name}-schedule-target"
arn = aws_lambda_function.lambda.arn
}
resource "aws_lambda_permission" "allow_cloudwatch_to_call_lambda" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.lambda.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.schedule.arn
}