Select your cookie preferences

We use cookies and similar tools to enhance your experience, provide our services, deliver relevant advertising, and make improvements. Approved third parties also use these tools to help us deliver advertising and provide certain site features.

EventBridge schedule to trigger a Step Functionsworkflow

Created with SnapScheduleStep Functionevery every day at 14:24

Simple pattern that triggers Step Functionsexecution once a day using EventBridge Scheduler with CDK and Python.

EventBridge Scheduler triggers a new Step Functionsexecution every 5 minutes.


## Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
## SPDX-License-Identifier: MIT-0

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Introduction to serverless for developers:part3 GitHub to Slack (uksb-1tthgi812) (tag:eventbridge-schedule-stepfunctions-sam)
  
##########################################################################
#  Parameters & Globals                                                  #
##########################################################################
Parameters:

Resources:
##########################################################################
#   Lambda Functions                                                      #
##########################################################################
    #  Order Manager SFN                                                   #
  GitHubTrafficTracker:
    Type: AWS::Serverless::StateMachine # More info about State Machine Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html
    Properties:
      DefinitionUri: statemachine/statemachine.asl.json

  # Schedule that will run every day at 00:00 to trigger process
  GitHubTrafficTrackerSchedule:
    Type: AWS::Scheduler::Schedule
    Properties:
      Description: Schedule the runs every day to start teh workflow
      FlexibleTimeWindow:
        Mode: 'OFF'
      ScheduleExpression: 'cron(24 14 * * ? *)'
      Target:
        Arn: !GetAtt GitHubTrafficTracker.Arn
        RoleArn: !GetAtt GitHubTrafficTrackerScheduleRole.Arn

  GitHubTrafficTrackerScheduleRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - scheduler.amazonaws.com
            Action:
              - sts:AssumeRole
      Policies:
        - PolicyName: invokeGitHubTrafficTrackerSFN
          PolicyDocument:
            Version: 2012-10-17
            Statement:
              - Effect: Allow
                Action:
                  - 'states:startExecution'
                Resource:
                  - !GetAtt GitHubTrafficTracker.Arn

< Back to all patterns


GitHub icon Visit the GitHub repo for this pattern.

Download

git clone https://github.com/aws-samples/serverless-patterns/ cd serverless-patterns/eventbridge-schedule-stepfunctions-sam

Deploy

sam build && sam deploy -g


Testing

See the README in the GitHub repo for detailed testing instructions.

Cleanup

Delete the stack: sam delete.

Benjamin Smith

Presented by Benjamin Smith

Ben is a senior developer advocate for Serverless Applications at Amazon Web Services based in London, UK. Prior to joining AWS Ben worked in a number of different technical roles specializing in workflow Automation and web development.

Follow on LinkedIn