Periodically Start a State Machine Execution Using CloudWatch Events - AWS Step Functions

Periodically Start a State Machine Execution Using CloudWatch Events

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

For more information about setting a Step Functions state machine as a target using the PutTarget Amazon CloudWatch Events API action, see Add a Step Functions state machine as a target.

Step 1: Create a State Machine

Before you can set a CloudWatch Events target, you must create a state machine.

  • To create a basic state machine, use the Getting Started tutorial.

  • If you already have a state machine, proceed to the next step.

Step 2: Create a CloudWatch Events Rule

After you create your state machine, you can create your CloudWatch Events rule.

  1. Navigate to the CloudWatch Events console, choose Events, and then choose Create Rule.

    The Step 1: Create rule page is displayed.

  2. In the Event source section, choose Schedule, and then enter 5 for Fixed rate of.

  3. In the Targets section, choose Add target, and then from the list choose Step Functions state machine.

  4. CloudWatch Events can create the IAM role needed for your event to run:

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

    • To use an IAM role that you created previously, choose Use existing role.

  5. Choose Configure details.

    The Step 2: Configure rule details page is displayed.

  6. Enter a Name for your rule (for example, statemachine-event), choose Enabled for State, and then choose Create rule.

    A new execution of your state machine starts every five minutes.