Menu
AWS Step Functions
Developer Guide

Starting a State Machine Execution Using CloudWatch Events

You can execute a Step Functions state machine in response to an event pattern or on a schedule using Amazon CloudWatch Events. This tutorial shows how to set a state machine as a target for a CloudWatch Events rule that starts the execution of a state machine every 5 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: Creating 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: Creating a CloudWatch Events Rule

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

To create the 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, select Schedule and type 5 for Fixed rate of.

  3. In the Targets section, choose Add target and 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, select Create a new role for this specific resource.

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

  5. Choose Configure details.

    The Step 2: Configure rule details page is displayed.

  6. Type a Name for your rule, choose Enabled for State, and then choose Create rule.

    The rule is created and the Rules page is displayed, listing all your CloudWatch Events rules.

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