Developing workflows with Step Functions
Learn how to define, develop, test, and debug your Amazon Step Functions state machines using the console, Amazon SDKs, Step Functions local, and various infrastructure as code frameworks.
Topics
- Defining your workflow
- Developing state machines in Step Functions console
- Visualizing workflows with the data flow simulator
- Using Amazon SDKs from Step Functions
- Calling HTTPS service APIs
- Choosing a region for endpoints
- Developing with Amazon CLI
- Developing with Step Functions Local
- Developing with Amazon Toolkit for Visual Studio Code
- Developing with Amazon SAM and Step Functions
- Developing with Terraform and Step Functions
- Using Workflow Studio
- Using Amazon SAM
- Using Workflow Studio inside Application Composer
- Using CloudFormation to create a workflow
- Using CDK to create a Standard workflow
- Using CDK to create an Express workflow
- Using Terraform to deploy workflows
- Using the Data Science SDK
Defining your workflow
Depending on your preference and tool, you can define your Step Functions state machines in JSON, YAML, or stringified Amazon States Language (ASL). definition that specifies the details of your state machine can be provided as either a string, or as a serialized object using JSON or YAML.
Note
YAML allows single line comments. Any YAML comments provided in the state machine
definition portion of a template will not be carried forward into the created
resource’s definition. Instead, you can use the Comment
property within
the state machine definition. For more information, see the State machine structure in Amazon States Language for Step Functions workflows page.
The following table shows which tools support ASL-based definitions.
Definition format support by tool | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
JSON | YAML | Stringified Amazon States Language | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Step Functions Console | ✓ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
HTTPS Service API | ✓ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Amazon CLI | ✓ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Step Functions Local | ✓ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Amazon Toolkit for Visual Studio Code | ✓ | ✓ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Amazon SAM | ✓ | ✓ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Amazon CloudFormation | ✓ | ✓ | ✓ |
Note
Amazon CloudFormation and Amazon SAM also allow you to upload your state machine definitions to Amazon S3 in JSON or YAML format, and to provide the definition's Amazon S3 location in the template. This can improve the readability of your templates when your state machine definition is complex. For more information see the AWS::StepFunctions::StateMachine S3Location page.
The following example Amazon CloudFormation templates show how you can provide the same state machine definition using different input formats.
Developing state machines in Step Functions console
You can design, develop, and debug workflows in the Step Functions console. You can define a
state machine in Amazon States Language, and create it in the Step Functions console
The Creating a Lambda State Machine tutorial uses this technique to create a simple state machine, execute it, and view its results.
Visualizing workflows with the data flow simulator
You control the flow of data in your workflows. You can use the data flow
simulator in the Step Functions consoleInputPath
,
Parameters
, ResultSelector
, OutputPath
, and
ResultPath
.
For more information, see Using data flow simulator to test data flow in Step Functions.
Using Amazon SDKs from Step Functions
Step Functions is supported by the Amazon SDKs for Java, .NET, Ruby, PHP, Python (Boto 3), JavaScript, Go, and C++. These SDKs provide a convenient way to use the Step Functions HTTPS API actions in multiple programming languages.
You can develop state machines, activities, or state machine starters using the API actions exposed by these SDK libraries. You can also access visibility operations using these libraries to develop your own Step Functions monitoring and reporting tools.
To use Step Functions with other Amazon services, see the reference documentation for the current
Amazon SDKs and Tools for Amazon Web
Services
Calling HTTPS service APIs
Step Functions provides service operations that are accessible through HTTPS requests. You can use these operations to communicate directly with Step Functions and to develop your own libraries in any language that can communicate with Step Functions through HTTPS.
You can develop state machines, workers, or state machine starters using the service API actions. You can also access visibility operations through the API actions to develop your own monitoring and reporting tools.
For detailed information about API actions, see the Amazon Step Functions API Reference.
Choosing a region for endpoints
To reduce latency and store data in a location that meets your requirements, Step Functions provides endpoints in different Amazon Regions.
Each endpoint in Step Functions is completely independent. A state machine or activity exists
only within the Region where it was created. Any state machines and activities that you
create in one Region don't share any data or attributes with those created in another
Region. For example, you can register a state machine named STATES-Flows-1
in
two different Regions. The STATES-Flows-1
state machine in one region won't
share data or attributes with the STATES-Flow-1
state machine in the other
region.
For a list of Step Functions endpoints, see Amazon Step Functions Regions and Endpoints in the Amazon Web Services General Reference.
Developing with Amazon CLI
You can access many Step Functions features from the Amazon Command Line Interface (Amazon CLI). The Amazon CLI is an
alternative to using the Step Functions console
You can use Step Functions commands in the Amazon CLI to start and manage executions, poll for activities, record task heartbeats, and more. For a complete list of Step Functions commands, descriptions of the available arguments, and examples showing their use, see the Amazon CLI Command Reference.
Amazon CLI commands follow the Amazon States Language closely, so you can use the Amazon CLI to learn about the Step Functions API actions. You can also use your existing API knowledge to prototype code or perform Step Functions actions from the command line.
Developing with Step Functions Local
For testing and development purposes, you can install and run Step Functions on your local machine. With Step Functions Local, you can start an execution on any machine.
The local version of Step Functions can invoke Amazon Lambda functions, both in Amazon and when running locally. You can also coordinate other supported Amazon services. For more information, see Testing state machines locally in Step Functions.
Note
Step Functions Local uses dummy accounts to work.
Developing with Amazon Toolkit for Visual Studio Code
You can use VS Code to interact with remote state machines and develop state machines locally. You can create or update state machines, list existing state machines, and execute or download a state machine. VS Code also lets you create new state machines from templates, see a visualization of your state machine, and provides code snippets, code completion, and code validation.
For more information, see the Amazon Toolkit for Visual Studio Code User Guide
Developing with Amazon SAM and Step Functions
You can use Amazon Serverless Application Model with Step Functions to build workflows and deploy the infrastructure you need, including Lambda functions, APIs and events, to create serverless applications. You can also use the Amazon SAM CLI in conjunction with the Amazon Toolkit for Visual Studio Code as part of an integrated experience.
For more information, see Using Amazon SAM to build Step Functions workflows.
Developing with Terraform and Step Functions
Terraform
For more information, see Using Terraform to deploy state machines in Step Functions.