Skip to content

Instantly share code, notes, and snippets.

@deegloo
Last active February 19, 2021 18:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deegloo/622b1065451d8a482cdb601f278245da to your computer and use it in GitHub Desktop.
Save deegloo/622b1065451d8a482cdb601f278245da to your computer and use it in GitHub Desktop.
Scheduling AWS Lambda execution using CloudWatch event rule
Description: >-
Schedule - the infrastructure.
AWSTemplateFormatVersion: 2010-09-09
Transform: "AWS::Serverless-2016-10-31"
Resources:
NotifierLambda:
Type: AWS::Serverless::Function
Properties:
FunctionName: 'notifier'
Handler: index.handler
CodeUri: 's3://deegloo-blog-post/schedule-notify-trigger/notifier-partial.zip'
Runtime: nodejs6.10
MemorySize: 1536
Timeout: 300
Environment:
Variables:
SOME_VARIABLE: 'some-value'
NotifierLambdaScheduledRule:
Type: AWS::Events::Rule
Properties:
Name: 'notifier-scheduled-rule'
Description: 'Triggers notifier lambda once per day'
ScheduleExpression: cron(0 7 ? * * *)
State: ENABLED
Targets:
-
Arn: !GetAtt NotifierLambda.Arn
Id: TargetFunctionV1
NotifierLambdaInvokePermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref NotifierLambda
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn: !GetAtt NotifierLambdaScheduledRule.Arn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment