Run AWS Step Functions state machines end-to-end locally, with per-step control over how each step runs.
Project description
AWS Step Functions Toolkit
Run a Step Functions state machine end-to-end on your laptop — and choose, per step, how each one runs.
The motivation to create this package was the need to test a Step Functions pipeline built almost
entirely from batch:submitJob.sync steps. AWS's
test_state
API does not currently support .sync integrations or .waitForTaskToken, and deploying and
running the state machine on AWS to validate each change made iterating impractical.
AWS's docs suggest chaining test_state calls
— feeding each state's output and next state into the next call — to exercise a complete execution
path, but leave you to build that driver loop yourself. This toolkit packages that logic as a
framework so you don't have to: it walks your real ASL definition state by state, delegates the
engine logic (Path/Parameters/ResultSelector/Output and next-state resolution) to test_state,
and handles the parts that aren't a linear chain — Map and Parallel fan-out, any-depth recursion,
and nested subflows. For the steps test_state cannot run (.sync, .waitForTaskToken), you
plug in a strategy — typically by building and running that step's container locally with
Docker. The result: run an entire pipeline locally and swap any step between a mock, your own
function, a local container, or a real AWS call.
The real console graph of the docker-batch example, annotated to show how the toolkit handles each state.
Install
pip install aws-stepfunctions-toolkit
Quick start
To run the bundled quickstart example (no Docker — its task steps are mocked), head to
examples/quickstart/ — it has step-by-step instructions. You'll need
AWS credentials + a region and an IAM role allowed to call test_state (see the
Setup guide).
What your code looks like
The snippet below shows the shape of a run — it is not runnable on its own (you supply your own state machine); the quickstart folder above is the runnable version.
import json
from aws_stepfunctions_toolkit import WorkflowRunner, StaticMockResponseStrategy, CallableStrategy
# Bring your own: your Step Functions state machine, exported as Amazon States Language (ASL)
# JSON. (In the AWS console: the state machine's "Definition" tab. This is the workflow you
# want to test — the toolkit does not generate it for you.)
definition = json.loads(open("state_machine.asl.json").read())
# For each step you don't want to run for real, say how to produce its result. Keys are the
# state names from your definition.
mock_mapping = {
# A mocked lambda:invoke result puts the function's return under "Payload" as a JSON string.
"Enrich": CallableStrategy(lambda data: {"Payload": json.dumps({"enriched": True})}), # your own function
"Notify": StaticMockResponseStrategy(json.dumps({"Payload": json.dumps({"status": "sent"})})), # a fixed payload
}
runner = WorkflowRunner(
role_arn="arn:aws:iam::<account>:role/<role-with-test-state-perms>", # the only value you must set; needs AWS creds + a region in your environment
asl_registry={"main": definition},
mock_mapping=mock_mapping,
)
final_output = runner.start(initial_input={"order_id": 123})
print(final_output)
asl_registry maps state-machine names to their ASL definitions: put the workflow you're testing
under the key "main" (the entry point). If your machine starts nested state machines (via
startExecution.sync:2), register each one too, keyed by the name of the state that starts it —
see Control flow.
JSONata throughout. The examples (and the toolkit's mock-result handling) use the JSONata query language. Set
"QueryLanguage": "JSONata"on each state (not just at the top level): the runner tests one state at a time, so a state must declare its own query language.
States without an entry in mock_mapping are handled automatically (test_state for
ordinary states; built-in recursion for Map / Parallel / nested state machines). To run a step
in a real local container instead of mocking it, use
DockerBatchStrategy.
Features
Each links to docs with a code snippet, or to a runnable example.
- Local end-to-end runs against your real ASL definition — no deploy. → runnable example
- Per-step execution choice —
test_state, a static mock, your own function, a local subprocess, a local Docker container, or a real AWS Batch submission. → docs/strategies.md - Pluggable image sources — plain Dockerfile (default), prebuilt/ECR image, or
docker buildx bake; bring your own. A bake file is not required. → docs/strategies.md#image-sources - Subflows (nested state machines) via
startExecution.sync:2. → docs/control-flow.md#subflows-nested-state-machines - Map and Parallel — fan-out and any-depth recursion. → docs/control-flow.md#map-states
- Run a sub-range — start and/or stop at specific states. → docs/control-flow.md#running-a-sub-range
- Container-side handler (
BatchJobInterface) for code inside your job containers. → docs/container-handler.md - Mock generation from a real execution, plus history inspection. → docs/cli-and-history.md
Documentation
Full documentation is hosted at aws-stepfunctions-toolkit.readthedocs.io.
| Page | What's in it |
|---|---|
| Setup | AWS credentials, the test_state IAM role, and Docker. |
| How it works | Motivation, the test_state gap, and the run loop. |
| Usage walkthrough | A complete, end-to-end worked example. |
| Selecting how each step runs | The strategy catalog + image sources. |
| Control flow | Subflows, Map/Parallel, recursion, start/end control. |
| Container-side handler | BatchJobInterface contract. |
| CLI & history | sfn-toolkit generate-mock, ExecutionHistory. |
Requirements
- Python 3.13+
- An AWS role/credentials allowed to call
test_state(the toolkit calls the real API for the engine logic). - Docker, only if you use
DockerBatchStrategyto run steps in containers.
New to this? The Setup guide covers AWS credentials, creating the
test_state IAM role, and Docker, step by step.
Examples
Each folder under examples/ is self-contained (its own ASL, runnable script, and
README) — see the examples index. Start with:
examples/quickstart/— copy-and-run starter; setROLE_ARNandpython run.py. No Docker (task steps are mocked).examples/local-subprocess/— run a step's code as a local subprocess (LocalExecutionStrategy). No Docker.examples/docker-batch/— run steps in real local containers (DockerfileImage+BakeImage) plus a nested machine.make run-exampleruns it (needs Docker, AWS creds, and aROLE_ARNenv var).
License
See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aws_stepfunctions_toolkit-0.1.1.tar.gz.
File metadata
- Download URL: aws_stepfunctions_toolkit-0.1.1.tar.gz
- Upload date:
- Size: 291.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bc2499aa11c41b9b60891f24a047d1132830a2d877b25aacee7742ee2f57c36
|
|
| MD5 |
acfaf84921f544b8cc0112f40ebe2c89
|
|
| BLAKE2b-256 |
bfd61704dbde38857542021bd0a7b6623412ad17d7525e841ab037fd77499f84
|
Provenance
The following attestation bundles were made for aws_stepfunctions_toolkit-0.1.1.tar.gz:
Publisher:
release.yml on compugen-ltd/aws-stepfunctions-toolkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aws_stepfunctions_toolkit-0.1.1.tar.gz -
Subject digest:
2bc2499aa11c41b9b60891f24a047d1132830a2d877b25aacee7742ee2f57c36 - Sigstore transparency entry: 2032762203
- Sigstore integration time:
-
Permalink:
compugen-ltd/aws-stepfunctions-toolkit@c54b31963e5460f6d11496f4f2560f6467f8f339 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/compugen-ltd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c54b31963e5460f6d11496f4f2560f6467f8f339 -
Trigger Event:
release
-
Statement type:
File details
Details for the file aws_stepfunctions_toolkit-0.1.1-py3-none-any.whl.
File metadata
- Download URL: aws_stepfunctions_toolkit-0.1.1-py3-none-any.whl
- Upload date:
- Size: 31.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59a58493b3e8e9ac2c5fe0e0533eff8d5c557116f1bd6c70651f0b07e63e87f8
|
|
| MD5 |
9839881d9b345843c9811016b868fe0c
|
|
| BLAKE2b-256 |
91cbb89602f2eece59676a8a0913ca8517fba08c213e814c60c438f5d6833cac
|
Provenance
The following attestation bundles were made for aws_stepfunctions_toolkit-0.1.1-py3-none-any.whl:
Publisher:
release.yml on compugen-ltd/aws-stepfunctions-toolkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aws_stepfunctions_toolkit-0.1.1-py3-none-any.whl -
Subject digest:
59a58493b3e8e9ac2c5fe0e0533eff8d5c557116f1bd6c70651f0b07e63e87f8 - Sigstore transparency entry: 2032762283
- Sigstore integration time:
-
Permalink:
compugen-ltd/aws-stepfunctions-toolkit@c54b31963e5460f6d11496f4f2560f6467f8f339 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/compugen-ltd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c54b31963e5460f6d11496f4f2560f6467f8f339 -
Trigger Event:
release
-
Statement type: