Skip to content

Instantly share code, notes, and snippets.

@brianknight10
Last active July 13, 2016 17:08
Show Gist options
  • Save brianknight10/ae584aa342e6f9c89f7fba73839e7e09 to your computer and use it in GitHub Desktop.
Save brianknight10/ae584aa342e6f9c89f7fba73839e7e09 to your computer and use it in GitHub Desktop.
Create a scheduled Lambda function using CloudWatch Event Rules
resource "aws_lambda_function" "check_foo" {
filename = "check_foo.zip"
function_name = "checkFoo"
role = "arn:aws:iam::424242:role/something"
handler = "index.handler"
}
resource "aws_cloudwatch_event_rule" "every_five_minutes" {
name = "every-five-minutes"
description = "Fires every five minutes"
schedule_expression = "rate(5 minutes)"
}
resource "aws_cloudwatch_event_target" "check_foo_every_five_minutes" {
rule = "${aws_cloudwatch_event_rule.every_five_minutes.name}"
target_id = "check_foo"
arn = "${aws_lambda_function.check_foo.arn}"
}
resource "aws_lambda_permission" "allow_cloudwatch_to_call_check_foo" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = "${aws_lambda_function.check_foo.function_name}"
principal = "events.amazonaws.com"
source_arn = "${aws_cloudwatch_event_rule.every_five_minutes.arn}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment