Adding a scheduled timer to start Lambda function resource using SAM

An example of how to add a scheduled timer to start the Lambda function in template.yaml of your SAM configuration

YourLambdaFunction:
    Type: AWS::Serverless::Function
    Properties:
      Description: Description of your function
      Runtime: nodejs16.x
      Architectures:
        - x86_64
      Handler: index.handler
      Events:
        CloudWatchEvent:
          Type: Schedule
          Properties:
            Schedule: rate(6 hours)
      MemorySize: 128
      Timeout: 100

With this example Lambda function will be executed every 6 hours.

More info on the available properties for the Lambda function creation is here. I use CDK documentation, as I have not found related to SAM resources.

Last updated