Skip to content

Instantly share code, notes, and snippets.

@andrew-templeton
Last active June 24, 2016 18:57
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 andrew-templeton/e79911115c05354a8ae6d8c94d10bb2c to your computer and use it in GitHub Desktop.
Save andrew-templeton/e79911115c05354a8ae6d8c94d10bb2c to your computer and use it in GitHub Desktop.
Generic lambda cron CloudFormation substack
{
"Parameters": {
"TARGET_LAMBDA_ARN": {
"Type": "String"
},
"EXEC_SCHEDULE": {
"Type": "String"
},
"RULE_NAME": {
"Type": "String"
}
},
"Resources": {
"LambdaScheduledJob": {
"DependsOn": [
"LambdaScheduledJobInvokeRole"
],
"Type": "AWS::Events::Rule",
"Properties": {
"Name": {
"Ref": "RULE_NAME"
},
"RoleArn": {
"Fn::GetAtt": [
"LambdaScheduledJobInvokeRole",
"Arn"
]
},
"ScheduleExpression": {
"Ref": "EXEC_SCHEDULE"
},
"State": "ENABLED",
"Targets": [
{
"Arn": {
"Ref": "TARGET_LAMBDA_ARN",
"Id": "lambda-cron"
}
}
]
}
},
"LambdaScheduledJobInvokeRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version" : "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"events.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"Path": "/",
"Policies": [
{
"PolicyName": "LambdaInvokePolicy",
"PolicyDocument": {
"Version" : "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "lambda:InvokeFunction",
"Resource": {
"Ref": "TARGET_LAMBDA_ARN"
}
}
]
}
}
]
}
}
},
"Outputs": {
"RuleId": {
"Description": "The event RuleId in CloudFormation",
"Value": {
"Ref": "LambdaScheduledJob"
}
},
"RuleArn": {
"Description": "The event ARN",
"Value": {
"Fn::GetAtt": [
"LambdaScheduledJob",
"Arn"
]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment