Using a Step Functions API action to continue a new execution (recommended) - Amazon Step Functions
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Using a Step Functions API action to continue a new execution (recommended)

Step Functions can start workflow executions by calling its own API as an integrated service. We recommend that you use this approach to avoid exceeding service quotas for long-running executions.

Step 1: Create a long-running state machine

Create a long-running state machine that you want to start from the Task state of a different state machine. For this tutorial, use the state machine that uses a Lambda function.


Make sure to copy the name and Amazon Resource Name of this state machine in a text file for later use.

Step 2: Create a state machine to call the Step Functions API action

To start workflow executions from a Task state

  1. Open the Step Functions console and choose Create state machine.

  2. On the Choose authoring method page, keep the default selections and choose Next.

  3. From the Actions tab, drag the StartExecution API action and drop it on the empty state labelled Drag first state here.

  4. Choose the StartExecution state and do the following in the Configuration tab:

    1. Rename the state to Start nested execution.

    2. For Integration type, choose Amazon SDK - new from the dropdown list.

    3. In API Parameters, for StateMachineArn, enter the Amazon Resource Name of a state machine. For example, enter the ARN of the state machine that uses Lambda.

    4. For Input, replace the existing placeholder text with the following value:

      "Comment": "Starting workflow execution using a Step Functions API action"
    5. Make sure your inputs in API Parameters look similar to the following:

      { "StateMachineArn": "arn:aws-cn:states:us-west-2:123456789012:stateMachine:LambdaStateMachine", "Input": { "Comment": "Starting workflow execution using a Step Functions API action", "AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID.$": "$$.Execution.Id" }
    6. Choose Next.

  5. (Optional) Review the automatically-generated Amazon States Language definition of your workflow and choose Next.

  6. On the Specify state machine settings page, enter a name for your state machine, such as ParentStateMachine, and then choose Create state machine.

Step 3: Update the IAM policy

To ensure your state machine has permissions to start the execution of the state machine that uses a Lambda function, you need to attach an inline policy to your state machine's IAM role. For more information, see Embedding Inline Policies in the IAM User Guide.

  1. On the page titled with your state machine name (ParentStateMachine), choose the IAM role ARN to navigate to the IAM Roles page for your state machine.

  2. Assign an appropriate permission to the ParentStateMachine IAM role for the state machine to start execution of another state machine. To assign the permission, do the following:

    1. On the IAM Roles page, choose Add permissions, and then choose Create inline policy.

    2. On the Create policy page, choose the JSON tab.

    3. Replace the existing text with the following policy.

      { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "states:StartExecution" ], "Resource": [ "arn:aws-cn:states:us-west-2:123456789012:stateMachine:LambdaStateMachine" ] } ] }
    4. Choose Review policy.

    5. Specify a name for the policy, and then choose Create policy.

Step 4: Start a new execution

  1. On the ParentStateMachine page, choose Start execution.

    The Start execution dialog box is displayed.

  2. Choose Start execution.

  3. Open the LambdaStateMachine state machine page and notice a new execution triggered by the ParentStateMachine.