Created
November 2, 2018 16:29
-
-
Save corpulentcoffee/844f2e360abe808aa5ad061d60c608fd to your computer and use it in GitHub Desktop.
Example CloudFormation template to setup a scheduled Lambda function using the Serverless transform
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
Transform: AWS::Serverless-2016-10-31 | |
Parameters: | |
Env: | |
Type: String | |
Default: test | |
DomainName: | |
Type: String | |
Default: www.example.com | |
Resources: | |
5MinMonitorLambda: | |
Type: AWS::Serverless::Function | |
Properties: | |
Handler: main.lambda_handler | |
Runtime: python3.6 | |
CodeUri: ./lambdas/_build/5-min-monitor | |
Environment: | |
Variables: | |
API_HOSTNAME: !Ref DomainName | |
FunctionName: !Sub ['${Env}-5-min-monitor', {Env: !Ref Env}] | |
Events: | |
Timer: | |
Type: Schedule | |
Properties: | |
Schedule: rate(5 minutes) | |
# After transformation, the above will expand to the following: | |
# - 5MinMonitorLambdaRole assumable by lambda.amazonaws.com w/ the basic | |
# AWSLambdaBasicExecutionRole policy attached for CloudWatch | |
# - 5MinMonitorLambda function | |
# - 5MinMonitorLambdaTimer rule setup to call function ever 5 minutes | |
# - 5MinMonitorLambdaTimerPermission policy allowing events.amazonaws.com | |
# to call 5MinMonitorLambda when the source is 5MinMonitorLambdaTimer | |
Lambda5MinMonitorLogGroup: | |
Type: AWS::Logs::LogGroup | |
Properties: | |
LogGroupName: !Sub ['/aws/lambda/${Func}', {Func: !Ref 5MinMonitorLambda}] | |
RetentionInDays: 90 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment