Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.