Last active
June 24, 2016 18:57
-
-
Save andrew-templeton/e79911115c05354a8ae6d8c94d10bb2c to your computer and use it in GitHub Desktop.
Generic lambda cron CloudFormation substack
This file contains hidden or 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
{ | |
"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