Skip to content
Snippets Groups Projects
Commit ab6d849a authored by nimrod's avatar nimrod
Browse files

Schedule per function.

There's a limit of 5 targets per rule. So rule per function it is.
parent 4a085ae4
No related branches found
No related tags found
No related merge requests found
Pipeline #1316 passed
......@@ -185,7 +185,7 @@ resource "aws_lambda_permission" "cloudwatch" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
principal = "events.amazonaws.com"
source_arn = local.cloudwatch_rule_arn
source_arn = local.cloudwatch_rule_arns[count.index]
function_name = local.function_names[count.index]
qualifier = local.function_alias_names[count.index]
}
......@@ -10,31 +10,32 @@ output "rate" {
}
resource "aws_cloudwatch_event_rule" "schedule" {
name = local.Name
description = "Schedule to trigger ${local.module} functions in ${local.env}."
count = length(local.function_names)
name = local.function_names[count.index]
description = "Schedule to trigger ${local.function_names[count.index]} 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
cloudwatch_rule_arns = aws_cloudwatch_event_rule.schedule.*.arn
cloudwatch_rule_names = 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_arns" {
description = "List of ARNs of the CloudWatch schedule rules."
value = local.cloudwatch_rule_arns
}
output "cloudwatch_rule_name" {
description = "Name of the CloudWatch schedule rule."
value = local.cloudwatch_rule_name
output "cloudwatch_rule_names" {
description = "List of names of the CloudWatch schedule rules."
value = local.cloudwatch_rule_names
}
resource "aws_cloudwatch_event_target" "schedule" {
count = length(local.function_alias_arns)
arn = local.function_alias_arns[count.index]
rule = local.cloudwatch_rule_name
rule = local.cloudwatch_rule_names[count.index]
depends_on = [
aws_lambda_permission.cloudwatch,
]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment