Skip to content

Commit

Permalink
Add scheduled trigger for lambda function
Browse files Browse the repository at this point in the history
  • Loading branch information
bobthemighty committed Mar 31, 2022
1 parent cba1303 commit e52e8e5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions infra/trigger.tf
@@ -0,0 +1,17 @@
resource "aws_cloudwatch_event_rule" "every_minute" {
name = "${var.lambda_function_name}-every-minute"
schedule_expression = "rate(1 minute)"
}

resource "aws_cloudwatch_event_target" "invoke_lambda" {
rule = aws_cloudwatch_event_rule.every_minute.name
arn = aws_lambda_function.lambda.arn
}

resource "aws_lambda_permission" "allow_cloudwatch" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = var.lambda_function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.every_minute.arn
}

0 comments on commit e52e8e5

Please sign in to comment.