EventBridge Scheduler – how to run tasks on a schedule at scale!

AWS released EventBridge Scheduler just a few months ago. This new feature of EventBridge allows you to create, run and manage scheduled tasks at scale. While EventBridge had a feature for running scheduled tasks before that one was not ideal because it had several limitations. For example you could not set one time tasks and you were limited in several other limitations like lower throughput and a minimal number of targets that you could set to your tasks.

EventBridge Scheduler comes to fix this and brings powerful new functionality and performance. I am not going to go into all the specifics in this post, you can click the link above with the announcement where you can read all about it.

I am just gonna show you how to set up scheduled tasks both from the console and programmatically through an AWS SAM template.

Console walkthrough

For the console walkthrough you can refer to the video below:

Programmatic creation of scheduled with AWS SAM

Below you can find the SAM template (which I also used in the video) and a link to the Github repo. Please make sure to change the SAM template according to your needs, for example change the StartDate, EndDate, Timezone

template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  eventbridge-scheduler-demo
  Sample SAM Template for eventbridge-scheduler-demo
  
Globals:
  Function:
    Timeout: 3

Resources:
  ScheduledFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: scheduled_function/
      Handler: app.lambdaHandler
      Runtime: nodejs16.x
      Architectures:
        - x86_64
      Events:
        ScheduledEventSource:
          Type: ScheduleV2
          Properties:
            ScheduleExpression: rate(2 minutes)
            FlexibleTimeWindow:
              Mode: FLEXIBLE
              MaximumWindowInMinutes: 15
            StartDate: '2023-02-03T13:15:00.000Z'
            EndDate: '2023-02-03T14:00:00.000Z'
            ScheduleExpressionTimezone: Europe/Bucharest
            Input: '{ "action": "dosomething"}'

For the full source code please refer to the following repository on Github: https://github.com/majestic-cloud/code-examples/blob/main/sam-templates/eventbridge/scheduler/eventbridge-scheduler-demo/template.yaml

I hope you find this useful. If you do please share it on your favorite platform.

Recent Articles

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here