AWS Step Functions
Overview
AWS Step Functions uses Amazon States Language (ASL) to define state machines as JSON. With AWS Step Functions, you can create workflows, also called State machines, to build distributed applications, automate processes, orchestrate microservices, and create data and machine learning pipelines.
This skill provides comprehensive guidance for writing state machines in ASL, covering:
- ASL structure and JSONata expression syntax
- Details on the eight available workflow states
- The
$states reserved variable
- Workflow variables with
Assign
- Error handling
- AWS Service integration patterns
- Example code for data transformation and architecture
- Validation and testing of state machines
- How to migrate from JSONPath to JSONata
When to Load Reference Files
Load the appropriate reference file based on what the user is working on:
- ASL structure, state types, Task, Pass, Choice, Wait, Succeed, Fail, Parallel, Map → see references/asl-state-types.md
- Error handling, troubleshooting, Retry, Catch, fallback, error codes, States.Timeout, States.ALL → see references/error-handling.md
- Service integrations, Lambda invoke, DynamoDB, SNS, SQS, SDK integrations, Resource ARN, sync, async → see references/service-integrations.md
- Migrating from JSONPath to JSONata, migration, JSONPath to JSONata, InputPath, Parameters, ResultSelector, ResultPath, OutputPath, intrinsic functions, Iterator, payload template → see references/migrating-from-jsonpath-to-jsonata.md
- Validation, linting, testing, TestState, test state, mock, mocking, unit test, inspection level, DEBUG, TRACE, validate state, test in isolation → see references/validation-and-testing.md
- Architecture patterns, examples, polling, saga, compensation, scatter-gather, semaphore, lock, human-in-the-loop, escalation, Express to Standard → see references/architecture-patterns.md
- Data transformation, JSONata expressions, filtering, aggregation, string operations, $reduce, $lookup, $toMillis, $partition, $parse, $hash, $uuid → see references/transforming-data.md
- State input/output, $states, Assign, Output, Arguments, variable scope, variable limits, evaluation order, passing data between states → see references/processing-state-inputs-and-outputs.md
- Deployment, SAM, CloudFormation, IaC, DefinitionSubstitutions, X-Ray tracing, logging → see the aws-serverless-deployment skill or deploy-on-aws plugin
Quick Reference
Standard vs Express Workflows
|
Standard |
Express |
| Max duration |
1 year |
5 minutes |
| Execution semantics |
Exactly-once |
At-least-once (async) / At-most-once (sync) |
| Execution history |
Retained 90 days, queryable via API |
CloudWatch Logs only |
| Max throughput |
2,000 exec/sec |
100,000 exec/sec |
| Pricing model |
Per state transition |
Per execution count + duration |
.sync / .waitForTaskToken |
Supported |
Not supported |
| Best for |
Auditable, non-idempotent operations |
High-volume, idempotent event processing |
Choose Standard for: payment processing, order fulfillment, compliance workflows, anything that must never execute twice.
Choose Express for: IoT data ingestion, streaming transformations, mobile backends, high-throughput short-lived processing.
Setting the State Machine Query Language
JSONata is the modern, preferred way to reference and transform data in ASL. It replaces the five JSONPath I/O fields (InputPath, Parameters, ResultSelector, ResultPath, OutputPath) with just two: Arguments (inputs) and Output.
Enable at the top level to apply to all states:
{ "QueryLanguage": "JSONata", "StartAt": "...", "States": {...} }
Or per-state to migrate from JSONPath incrementally:
{ "Type": "Task", "QueryLanguage": "JSONata", ... }
JSONPath is still supported and is the default if QueryLanguage is omitted — existing state machines do not need to be migrated.
Best Practices
- Set
"QueryLanguage": "JSONata" at the top level for new state machines unless the user wants to use JSONPath
- Keep
Output minimal — only include what the state immediately after the current state needs
- Use
Assign to store variables needed in later states instead of threading it through Output
- Use
$states.input to reference original state input
- Remember:
Assign and Output are evaluated in parallel — variable assignments in Assign are NOT available in Output of the same state
- All JSONata expressions must produce a defined value —
$data.nonExistentField throws States.QueryEvaluationError
- Use
$states.context.Execution.Input to access the original workflow input from any state
- Save state machine definitions with
.asl.json extension when working outside the console
- Prefer the optimized Lambda integration (
arn:aws:states:::lambda:invoke) over the SDK integration
Troubleshooting
Common Errors
States.QueryEvaluationError — JSONata expression failed. Check for type errors, undefined fields, or out-of-range values.
- Mixing JSONPath fields with JSONata fields in the same state.
- Using
$ or $$ at the top level of a JSONata expression — use $states.input instead.
- Forgetting
{% %} delimiters around JSONata expressions — the string will be treated as a literal.
- Assigning variables in
Assign and expecting them in Output of the same state — new values only take effect in the next state.
- Reference references/validation-and-testing.md and references/error-handling.md for detailed troubleshooting information.
Resources
1---2name: aws-step-functions3description: Build workflows with AWS Step Functions state machines using the JSONata query language. Covers Amazon States Language (ASL) structure, state types, variables, data transformation, error handling, AWS service integration, and migrating from the JSONPath to the JSONata query language.4---5
6# AWS Step Functions
7
8## Overview
9
10AWS Step Functions uses Amazon States Language (ASL) to define state machines as JSON. With AWS Step Functions, you can create workflows, also called State machines, to build distributed applications, automate processes, orchestrate microservices, and create data and machine learning pipelines.
11
12This skill provides comprehensive guidance for writing state machines in ASL, covering:
13
14- ASL structure and JSONata expression syntax
15- Details on the eight available workflow states
16- The `$states` reserved variable
17- Workflow variables with `Assign`
18- Error handling
19- AWS Service integration patterns
20- Example code for data transformation and architecture
21- Validation and testing of state machines
22- How to migrate from JSONPath to JSONata
23
24## When to Load Reference Files
25
26Load the appropriate reference file based on what the user is working on:
27
28- **ASL structure**, **state types**, **Task**, **Pass**, **Choice**, **Wait**, **Succeed**, **Fail**, **Parallel**, **Map** → see [references/asl-state-types.md](references/asl-state-types.md)
29- **Error handling**, **troubleshooting**, **Retry**, **Catch**, **fallback**, **error codes**, **States.Timeout**, **States.ALL** → see [references/error-handling.md](references/error-handling.md)
30- **Service integrations**, **Lambda invoke**, **DynamoDB**, **SNS**, **SQS**, **SDK integrations**, **Resource ARN**, **sync**, **async** → see [references/service-integrations.md](references/service-integrations.md)
31- **Migrating from JSONPath to JSONata**, **migration**, **JSONPath to JSONata**, **InputPath**, **Parameters**, **ResultSelector**, **ResultPath**, **OutputPath**, **intrinsic functions**, **Iterator**, **payload template** → see [references/migrating-from-jsonpath-to-jsonata.md](references/migrating-from-jsonpath-to-jsonata.md)
32- **Validation**, **linting**, **testing**, **TestState**, **test state**, **mock**, **mocking**, **unit test**, **inspection level**, **DEBUG**, **TRACE**, **validate state**, **test in isolation** → see [references/validation-and-testing.md](references/validation-and-testing.md)
33- **Architecture patterns**, **examples**, **polling**, **saga**, **compensation**, **scatter-gather**, **semaphore**, **lock**, **human-in-the-loop**, **escalation**, **Express to Standard** → see [references/architecture-patterns.md](references/architecture-patterns.md)
34- **Data transformation**, **JSONata expressions**, **filtering**, **aggregation**, **string operations**, **$reduce**, **$lookup**, **$toMillis**, **$partition**, **$parse**, **$hash**, **$uuid** → see [references/transforming-data.md](references/transforming-data.md)
35- **State input/output**, **$states**, **Assign**, **Output**, **Arguments**, **variable scope**, **variable limits**, **evaluation order**, **passing data between states** → see [references/processing-state-inputs-and-outputs.md](references/processing-state-inputs-and-outputs.md)
36- **Deployment**, **SAM**, **CloudFormation**, **IaC**, **DefinitionSubstitutions**, **X-Ray tracing**, **logging** → see the [aws-serverless-deployment skill](../aws-serverless-deployment/) or [deploy-on-aws plugin](../../deploy-on-aws/)
37
38## Quick Reference
39
40### Standard vs Express Workflows
41
42| | Standard | Express |
43| --------------------------------- | ------------------------------------ | ------------------------------------------- |
44| **Max duration** | 1 year | 5 minutes |
45| **Execution semantics** | Exactly-once | At-least-once (async) / At-most-once (sync) |
46| **Execution history** | Retained 90 days, queryable via API | CloudWatch Logs only |
47| **Max throughput** | 2,000 exec/sec | 100,000 exec/sec |
48| **Pricing model** | Per state transition | Per execution count + duration |
49| **`.sync` / `.waitForTaskToken`** | Supported | Not supported |
50| **Best for** | Auditable, non-idempotent operations | High-volume, idempotent event processing |
51
52**Choose Standard** for: payment processing, order fulfillment, compliance workflows, anything that must never execute twice.
53
54**Choose Express** for: IoT data ingestion, streaming transformations, mobile backends, high-throughput short-lived processing.
55
56### Setting the State Machine Query Language
57
58JSONata is the modern, preferred way to reference and transform data in ASL. It replaces the five JSONPath I/O fields (`InputPath`, `Parameters`, `ResultSelector`, `ResultPath`, `OutputPath`) with just two: `Arguments` (inputs) and `Output`.
59
60**Enable at the top level** to apply to all states:
61
62```json
63{ "QueryLanguage": "JSONata", "StartAt": "...", "States": {...} }
64```
65
66**Or per-state** to migrate from JSONPath incrementally:
67
68```json
69{ "Type": "Task", "QueryLanguage": "JSONata", ... }
70```
71
72**JSONPath is still supported** and is the default if `QueryLanguage` is omitted — existing state machines do not need to be migrated.
73
74## Best Practices
75
76- Set `"QueryLanguage": "JSONata"` at the top level for new state machines unless the user wants to use JSONPath
77- Keep `Output` minimal — only include what the state immediately after the current state needs
78- Use `Assign` to store variables needed in later states instead of threading it through Output
79- Use `$states.input` to reference original state input
80- Remember: `Assign` and `Output` are evaluated in parallel — variable assignments in `Assign` are NOT available in `Output` of the same state
81- All JSONata expressions must produce a defined value — `$data.nonExistentField` throws `States.QueryEvaluationError`
82- Use `$states.context.Execution.Input` to access the original workflow input from any state
83- Save state machine definitions with `.asl.json` extension when working outside the console
84- Prefer the optimized Lambda integration (`arn:aws:states:::lambda:invoke`) over the SDK integration
85
86## Troubleshooting
87
88### Common Errors
89
90- `States.QueryEvaluationError` — JSONata expression failed. Check for type errors, undefined fields, or out-of-range values.
91- Mixing JSONPath fields with JSONata fields in the same state.
92- Using `$` or `$$` at the top level of a JSONata expression — use `$states.input` instead.
93- Forgetting `{% %}` delimiters around JSONata expressions — the string will be treated as a literal.
94- Assigning variables in `Assign` and expecting them in `Output` of the same state — new values only take effect in the next state.
95- Reference [references/validation-and-testing.md](references/validation-and-testing.md) and [references/error-handling.md](references/error-handling.md) for detailed troubleshooting information.
96
97## Resources
98
99- [ASL Specification](https://states-language.net/spec.html)
100- [JSONata documentation](https://docs.jsonata.org/overview.html)
101- [Step Functions Developer Guide](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html)