Last active
November 13, 2018 16:18
-
-
Save groovili/1a89d0c8077103bf44821e1b40cfd783 to your computer and use it in GitHub Desktop.
AWS CloudWatch schedule for lambda execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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