Periodically start a state machine execution using EventBridge - AWS Step Functions

Periodically start a state machine execution using EventBridge

You can execute an AWS Step Functions state machine in response to an event pattern or on a schedule using Amazon EventBridge. This tutorial shows you how to set a state machine as a target for an EventBridge rule that starts the periodic execution of a state machine based on the schedule you define.

Step 1: Create a State Machine

Before you can set an EventBridge target, you must create a state machine.

Step 2: Create an EventBridge Rule

After you create your state machine, you can create your EventBridge rule.

  1. Navigate to the Amazon EventBridge console, and choose Create rule.

    Alternatively, on the Amazon EventBridge console, choose Rules, and then choose Create rules.

  2. On the Define rule detail page, enter a name and description for the rule.


    A rule can't have the same name as another rule in the same Region and on the same event bus.

  3. For Event bus, choose the event bus that you want to associate with this rule. If you want this rule to match events that come from your account, choose default. When an AWS service in your account emits an event, it always goes to your account’s default event bus.

  4. For Rule type, choose Schedule.

  5. Choose Next.

  6. On the Define schedule page, for Schedule pattern, do one of the following:

    • To use a cron expression to define the schedule, choose A fine-grained schedule that runs at a specific time, such as 8:00 a.m. PST on the first Monday of every month. and enter the cron expression.

    • To use a rate expression to define the schedule, choose A schedule that runs at a regular rate, such as every 10 minutes. and enter the rate expression.

  7. Choose Next.

  8. On the Select target(s) page, for Target types, choose AWS service.

  9. For Select a target, choose Step Functions state machine.

  10. For State machine, choose the state machine that you want to run periodically.

  11. For Execution role, do one of the following:

    • To create an IAM role automatically, choose Create a new role for this specific resource.

    • To use an IAM role that you created earlier, choose Use existing role and choose the existing role from the drop-down list.

  12. Choose Next.

  13. (Optional) On the Configure tags page, enter one or more tags for the rule.

  14. Choose Next.

  15. On the Review and create page, review the details of the rule and choose Create rule.

Example of Execution Input

The following example shows a typical input to the state machine execution.

{ "version": "0", "id": "6c540ad4-0671-9974-6511-756fb789fced", "detail-type": "Scheduled Event", "source": "", "account": "123456789012", "time": "2022-03-26T00:01:02Z", "region": "us-east-1", "resources": [ "arn:aws:sm:::rule/my-state-machine" ], "detail": {} }