This sample project demonstrates how to use an AWS Step Functions state machine to launch other state machine executions.
The state machine combines workflows using a Step Functions StartExecution task state with various integration patterns.
Learn more about this workflow at Step Functions workflows collection: << Add the live URL here >>
Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
- Create an AWS account if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
- AWS CLI installed and configured
- Git Installed
- AWS CDK Installed
- If this is your first time using AWS CDK, bootstrap your environment.
cdk bootstrap aws://{your-aws-account-number}/{your-aws-region}
- Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
git clone https://github.com/aws-samples/step-functions-workflows-collection
- Change directory to the pattern directory:
cd workflow-within-a-workflow-cdk
- From the command line, use npm to install dependencies and run the build process:
npm install npm run build
- From the command line, use CDK to deploy the AWS resources for the workflow.
cdk deploy
- During the prompts:
Do you wish to deploy these changes (y/n)? Y
- Note the outputs from the cdk deployment process. The State Machine Name and ARN are outputted for testing.
- When the main state machine is executed, it will first start executing the nested state machine using the call and continue integration pattern. This integration pattern means that the main state machine will call an API (StartExecution), receive an HTTP response and then continue to the next step.
- In parallel, the main state machine will then execute the nested state machine using wait for child execution to complete on one branch, and wait for callback on another branch.
- When the main state machine starts executing the nested state machine using the wait for child execution to complete integration pattern, this causes the main state machine to pause the execution at this state and monitor the nested state machine's execution. The main state machine will resume when the nested state machine's execution is complete.
- When the main state machine starts executing the nested state machine using the wait for callback integration pattern, this causes the main state machine to pause the execution until it receives a callback from the SendTaskSuccess or SendTaskFailure APIs with the task token. The nested state machine's Lambda function will send a SendTaskSuccess API call when this integration pattern is chosen.
- Start a new step functions execution for the main state machine
- Navigate to the AWS Step Functions console and choose NestedPatternMainStateMachine, then choose Start execution
- On the New execution page, enter an execution name (optional), and then choose Start execution.
- When an execution is complete, you can select states on the Visual workflow and browse the Input and Output under Step details.
- Examine the nested state machine's execution based on the different integration patterns.
- Navigate to the AWS Step Functions console and choose NestedStateMachine.
- Examine the execution logs under Executions. You should see three different execution logs for each execution started.
- Choose the log name for each execution and notice the different paths that the state machine takes based on the integration pattern chosed by the main state machine. You can also select states on the Visual workflow and browse the Input and Output under Step details.
- Delete the stack
cdk destroy
- During the prompts:
Are you sure you want to delete: WorkflowWithinAWorkflowCdkStack (y/n)? Y
Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0