Manage time-based events with EventBridge Scheduler in Amazon SAM - Amazon Serverless Application Model
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Manage time-based events with EventBridge Scheduler in Amazon SAM

The content in this topic provides details on what Amazon EventBridge Scheduler is, what support Amazon SAM offers, how you can create Scheduler events, and examples you can reference when creating Scheduler events.

What is Amazon EventBridge Scheduler?

Use EventBridge Scheduler to schedule events in your Amazon SAM templates. Amazon EventBridge Scheduler is a scheduling service that lets you create, initiate, and manage tens of millions of events and tasks across all Amazon services. This service is particularly useful for time-related events. You can use it to schedule events and recurring time-based invocations. It also supports one-time events as well as rate and chron expressions with a start and end time.

To learn more about Amazon EventBridge Scheduler, see What is Amazon EventBridge Scheduler? in the EventBridge Scheduler User Guide.

EventBridge Scheduler support in Amazon SAM

The Amazon Serverless Application Model (Amazon SAM) template specification provides a simple, short-hand syntax that you can use to schedule events with EventBridge Scheduler for Amazon Lambda and Amazon Step Functions.

Creating EventBridge Scheduler events in Amazon SAM

Set the ScheduleV2 property as the event type in your Amazon SAM template to define your EventBridge Scheduler event. This property supports the AWS::Serverless::Function and AWS::Serverless::StateMachine resource types.

MyFunction: Type: AWS::Serverless::Function Properties: Events: CWSchedule: Type: ScheduleV2 Properties: ScheduleExpression: 'rate(1 minute)' Name: TestScheduleV2Function Description: Test schedule event MyStateMachine: Type: AWS::Serverless::StateMachine Properties: Events: CWSchedule: Type: ScheduleV2 Properties: ScheduleExpression: 'rate(1 minute)' Name: TestScheduleV2StateMachine Description: Test schedule event

EventBridge Scheduler event scheduling also supports dead-letter queues (DLQ) for unprocessed events. For more information on dead-letter queues, see Configuring a dead-letter queue for EventBridge Scheduler in the EventBridge Scheduler User Guide.

When a DLQ ARN is specified, Amazon SAM configures permissions for the Scheduler schedule to send messages to the DLQ. When a DLQ ARN is not specified, Amazon SAM will create the DLQ resource.

Examples

Basic example of defining an EventBridge Scheduler event with Amazon SAM

Transform: AWS::Serverless-2016-10-31 Resources: MyLambdaFunction: Type: AWS::Serverless::Function Properties: Handler: index.handler Runtime: python3.8 InlineCode: | def handler(event, context): print(event) return {'body': 'Hello World!', 'statusCode': 200} MemorySize: 128 Events: Schedule: Type: ScheduleV2 Properties: ScheduleExpression: rate(1 minute) Input: '{"hello": "simple"}' MySFNFunction: Type: AWS::Serverless::Function Properties: Handler: index.handler Runtime: python3.8 InlineCode: | def handler(event, context): print(event) return {'body': 'Hello World!', 'statusCode': 200} MemorySize: 128 StateMachine: Type: AWS::Serverless::StateMachine Properties: Type: STANDARD Definition: StartAt: MyLambdaState States: MyLambdaState: Type: Task Resource: !GetAtt MySFNFunction.Arn End: true Policies: - LambdaInvokePolicy: FunctionName: !Ref MySFNFunction Events: Events: Schedule: Type: ScheduleV2 Properties: ScheduleExpression: rate(1 minute) Input: '{"hello": "simple"}'

Learn more

To learn more about defining the ScheduleV2 EventBridge Scheduler property, see: