Start a Workflow within a Workflow (Step Functions, Lambda) - 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.

Start a Workflow within a Workflow (Step Functions, Lambda)

This sample project demonstrates how to use an Amazon Step Functions state machine to launch other state machine executions. See Start Workflow Executions from a Task State.

Create the State Machine and Provision Resources

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

  2. Choose Sample Projects, and then choose Start a Workflow Within a Workflow.

    The state machine Code and Visual Workflow are displayed.

          Start a workflow.
  3. Choose Next.

    The Deploy resources page is displayed, listing the resources that will be created. For this sample project, the resources include:

    • An additional Step Functions state machine

    • A Lambda function for callback

  4. Choose Deploy Resources.


    It can take up to 10 minutes for these resources and related IAM permissions to be created. While the Deploy resources page is displayed, you can open the Stack ID link to see which resources are being provisioned.

Start a New Execution

  1. On the New execution page, enter an execution name (optional), and then choose Start Execution.

  2. (Optional) To identify your execution, you can specify a name for it in the Name box. By default, Step Functions generates a unique execution name automatically.


    Step Functions allows you to create state machine, execution, and activity names that contain non-ASCII characters. These non-ASCII names don't work with Amazon CloudWatch. To ensure that you can track CloudWatch metrics, choose a name that uses only ASCII characters.

  3. Optionally, you can go to the newly created state machine on the Step Functions Dashboard, and then choose New execution.

  4. When an execution is complete, you can select states on the Visual workflow and browse the Input and Output under Step details.

Example State Machine Code

The state machine in this sample project integrates another state machine and Amazon Lambda by passing parameters directly to those resources.

Browse through this example state machine to see how Step Functions calls the StartExecution API action for the other state machine. It launches two instances of the other state machine in parallel: one using the Run a Job (.sync) pattern and one using the Wait for a Callback with the Task Token pattern.

For more information about how Amazon Step Functions can control other Amazon services, see Using Amazon Step Functions with other services.

{ "Comment": "An example of combining workflows using a Step Functions StartExecution task state with various integration patterns.", "StartAt": "Start new workflow and continue", "States": { "Start new workflow and continue": { "Comment": "Start an execution of another Step Functions state machine and continue", "Type": "Task", "Resource": "arn:aws:states:::states:startExecution", "Parameters": { "StateMachineArn": "arn:aws:states:us-east-1:123456789012:stateMachine:NestingPatternAnotherStateMachine-HZ9gtgspmdun", "Input": { "NeedCallback": false, "AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID.$": "$$.Execution.Id" } }, "Next": "Start in parallel" }, "Start in parallel": { "Comment": "Start two executions of the same state machine in parallel", "Type": "Parallel", "End": true, "Branches": [ { "StartAt": "Start new workflow and wait for completion", "States": { "Start new workflow and wait for completion": { "Comment": "Start an execution of the same 'NestingPatternAnotherStateMachine' and wait for its completion", "Type": "Task", "Resource": "arn:aws:states:::states:startExecution.sync", "Parameters": { "StateMachineArn": "arn:aws:states:us-east-1:123456789012:stateMachine:NestingPatternAnotherStateMachine-HZ9gtgspmdun", "Input": { "NeedCallback": false, "AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID.$": "$$.Execution.Id" } }, "OutputPath": "$.Output", "End": true } } }, { "StartAt": "Start new workflow and wait for callback", "States": { "Start new workflow and wait for callback": { "Comment": "Start an execution and wait for it to call back with a task token", "Type": "Task", "Resource": "arn:aws:states:::states:startExecution.waitForTaskToken", "Parameters": { "StateMachineArn": "arn:aws:states:us-east-1:123456789012:stateMachine:NestingPatternAnotherStateMachine-HZ9gtgspmdun", "Input": { "NeedCallback": true, "AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID.$": "$$.Execution.Id", "TaskToken.$": "$$.Task.Token" } }, "End": true } } } ] } } }

For information about how to configure IAM when using Step Functions with other Amazon services, see IAM Policies for integrated services.