Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@groovili
Last active November 13, 2018 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groovili/1a89d0c8077103bf44821e1b40cfd783 to your computer and use it in GitHub Desktop.
Save groovili/1a89d0c8077103bf44821e1b40cfd783 to your computer and use it in GitHub Desktop.
AWS CloudWatch schedule for lambda execution
resource "aws_lambda_function" "check" {
filename = "./check.zip"
function_name = "check"
role = "arn:aws:iam::424242:role/something"
handler = "main"
runtime = "go1.x"
source_code_hash = "${base64sha256(file("./check.zip"))}"
}
resource "aws_cloudwatch_event_rule" "every_twelve_hours" {
name = "every-twelve-hours"
description = "Fires every twelve hours"
schedule_expression = "cron(0 12 * * ? *)"
}
resource "aws_cloudwatch_event_target" "check_every_twelve_hours" {
rule = "${aws_cloudwatch_event_rule.every_twelve_hours.name}"
target_id = "check"
arn = "${aws_lambda_function.check.arn}"
}
resource "aws_lambda_permission" "allow_cloudwatch_to_call_check" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = "${aws_lambda_function.check.function_name}"
principal = "events.amazonaws.com"
source_arn = "${aws_cloudwatch_event_rule.every_twelve_hours.arn}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment