2023-04-13 11:38:14 -07:00
<!--Generated by WRITEME on 2023-04-12 00:07:52.202277 (UTC)-->
2023-02-22 04:14:45 -08:00
# Step Functions code examples for the SDK for Python
2021-01-15 17:18:54 -08:00
2023-02-22 04:14:45 -08:00
## Overview
2021-01-15 17:18:54 -08:00
2023-02-22 04:14:45 -08:00
Shows how to use the AWS SDK for Python (Boto3) to work with AWS Step Functions.
2021-01-15 17:18:54 -08:00
2023-02-22 04:14:45 -08:00
<!--custom.overview.start-->
<!--custom.overview.end-->
* Step Functions makes it easy to coordinate the components of distributed applications as a series of steps in a visual workflow. *
## ⚠ Important
* Running this code might result in charges to your AWS account.
* Running the tests might result in charges to your AWS account.
* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege ](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege ).
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services ](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services ).
<!--custom.important.start-->
<!--custom.important.end-->
2021-01-15 17:18:54 -08:00
2021-11-10 11:20:31 -08:00
## Code examples
2023-04-13 11:38:14 -07:00
### Prerequisites
For prerequisites, see the [README ](../../README.md#Prerequisites ) in the `python` folder.
Install the packages required by these examples by running the following in a virtual environment:
```
python -m pip install -r requirements.txt
```
<!--custom.prerequisites.start-->
<!--custom.prerequisites.end-->
2023-02-22 04:14:45 -08:00
### Get started
2021-11-10 11:20:31 -08:00
2023-02-22 04:14:45 -08:00
* [Hello Step Functions ](hello.py#L4 ) (`ListStateMachines` )
### Single actions
Code excerpts that show you how to call individual service functions.
2021-01-15 17:18:54 -08:00
2023-02-22 04:14:45 -08:00
* [Create a state machine ](state_machines.py#L28 ) (`CreateStateMachine` )
* [Create an activity ](activities.py#L31 ) (`CreateActivity` )
* [Delete a state machine ](state_machines.py#L138 ) (`DeleteStateMachine` )
* [Delete an activity ](activities.py#L118 ) (`DeleteActivity` )
* [Describe a state machine ](state_machines.py#L75 ) (`DescribeStateMachine` )
* [Describe a state machine run ](state_machines.py#L118 ) (`DescribeExecution` )
* [Get task data for an activity ](activities.py#L73 ) (`GetActivityTask` )
* [List activities ](activities.py#L51 ) (`ListActivities` )
* [List state machines ](state_machines.py#L53 ) (`ListStateMachines` )
* [Send a success response to a task ](activities.py#L95 ) (`SendTaskSuccess` )
* [Start a state machine run ](state_machines.py#L95 ) (`StartExecution` )
2021-01-15 17:18:54 -08:00
2023-02-22 04:14:45 -08:00
### Scenarios
Code examples that show you how to accomplish a specific task by calling multiple
functions within the same service.
* [Get started with state machines ](get_started_state_machines.py )
### Cross-service examples
Sample applications that work across multiple AWS services.
* [Create a messenger application ](../../cross_service/stepfunctions_messenger )
## Run the examples
2021-01-15 17:18:54 -08:00
2023-02-22 04:14:45 -08:00
### Instructions
2021-11-10 11:20:31 -08:00
2023-03-31 05:36:53 -07:00
2023-02-22 04:14:45 -08:00
<!--custom.instructions.start-->
<!--custom.instructions.end-->
2021-01-15 17:18:54 -08:00
2023-02-22 04:14:45 -08:00
#### Hello Step Functions
2021-01-15 17:18:54 -08:00
2023-02-22 04:14:45 -08:00
This example shows you how to get started using Step Functions.
2021-01-15 17:18:54 -08:00
2023-02-22 04:14:45 -08:00
```
python hello.py
```
2021-01-15 17:18:54 -08:00
2023-04-13 11:38:14 -07:00
2023-02-22 04:14:45 -08:00
#### Get started with state machines
2021-01-15 17:18:54 -08:00
2023-02-22 04:14:45 -08:00
This example shows you how to do the following:
2021-01-15 17:18:54 -08:00
2023-02-22 04:14:45 -08:00
* Create an activity.
* Create a state machine from an Amazon States Language definition that contains the previously created activity as a step.
* Run the state machine and respond to the activity with user input.
2023-03-31 05:36:53 -07:00
* Get the final status and output after the run completes, then clean up resources.
2021-01-15 17:18:54 -08:00
2023-04-13 11:38:14 -07:00
<!--custom.scenario_prereqs.sfn_Scenario_GetStartedStateMachines.start-->
<!--custom.scenario_prereqs.sfn_Scenario_GetStartedStateMachines.end-->
2023-02-22 04:14:45 -08:00
Start the example by running the following at a command prompt:
```
python get_started_state_machines.py
2021-01-15 17:18:54 -08:00
```
2023-02-22 04:14:45 -08:00
<!--custom.scenarios.sfn_Scenario_GetStartedStateMachines.start-->
<!--custom.scenarios.sfn_Scenario_GetStartedStateMachines.end-->
2021-01-15 17:18:54 -08:00
2023-02-22 04:14:45 -08:00
### Tests
⚠ Running tests might result in charges to your AWS account.
2023-03-31 05:36:53 -07:00
2023-02-22 04:14:45 -08:00
To find instructions for running these tests, see the [README ](../../README.md#Tests )
in the `python` folder.
2023-03-31 05:36:53 -07:00
2023-02-22 04:14:45 -08:00
<!--custom.tests.start-->
<!--custom.tests.end-->
## Additional resources
* [Step Functions Developer Guide ](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html )
* [Step Functions API Reference ](https://docs.aws.amazon.com/step-functions/latest/apireference/Welcome.html )
* [SDK for Python Step Functions reference ](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/stepfunctions.html )
<!--custom.resources.start-->
<!--custom.resources.end-->
2021-01-15 17:18:54 -08:00
---
2023-02-22 04:14:45 -08:00
2021-01-15 17:18:54 -08:00
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2023-02-22 04:14:45 -08:00
SPDX-License-Identifier: Apache-2.0