Newer
Older
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
variable "rate" {
default = 15
description = "How often in minutes the Lambda functions will trigger."
type = number
}
output "rate" {
description = "How often in minutes the Lambda functions will trigger."
value = var.rate
}
resource "aws_cloudwatch_event_rule" "schedule" {
name = local.Name
description = "Schedule to trigger ${local.module} functions in ${local.env}."
schedule_expression = "rate(${var.rate} minutes)"
tags = local.common_tags
}
locals {
cloudwatch_rule_arn = aws_cloudwatch_event_rule.schedule.arn
cloudwatch_rule_name = aws_cloudwatch_event_rule.schedule.name
}
output "cloudwatch_rule_arn" {
description = "ARN of the CloudWatch schedule rule."
value = local.cloudwatch_rule_arn
}
output "cloudwatch_rule_name" {
description = "Name of the CloudWatch schedule rule."
value = local.cloudwatch_rule_name
}
resource "aws_cloudwatch_event_target" "schedule" {
count = length(local.function_arns)
arn = local.function_alias_arns[count.index]
rule = local.cloudwatch_rule_name
depends_on = [
aws_lambda_permission.cloudwatch,
]
}