npx skills add ...
npx skills add aws/agent-toolkit-for-aws --skill aws-step-functions
Authors and edits AWS Step Functions state machines: writes Amazon States Language (ASL) in JSONata, and chooses and structures state types (Task, Choice, Map, Parallel, Pass, Wait, Succeed, Fail). Covers ASL syntax, JSONata data transformation and variables, Retry/Catch error handling, service integrations (.sync, waitForTaskToken callbacks), Distributed Map for large-scale S3/CSV processing, saga/compensation patterns, Standard vs Express workflow choice, TestState API unit testing, and migrating state machines from JSONPath to JSONata. Use when the user is building, authoring, debugging, or migrating a Step Functions state machine or ASL definition, or orchestrating multi-step workflows with branching, retries, or human-approval callbacks, even if they don't say 'Step Functions.' Do NOT use for general Lambda function code, API Gateway, EventBridge wiring, or SAM/CDK application packaging.
npx skills add aws/agent-toolkit-for-aws --skill aws-step-functions
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:
$states reserved variableAssignThe AWS MCP server is recommended for sandboxed execution and audit logging when following this skill, but all steps use AWS CLI syntax and work without it.
Load the appropriate reference file based on what the user is working on:
references/asl-state-types.mdreferences/error-handling.mdreferences/service-integrations.mdreferences/migrating-from-jsonpath-to-jsonata.mdreferences/validation-and-testing.mdreferences/architecture-patterns.mdreferences/transforming-data.mdreferences/processing-state-inputs-and-outputs.md| 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.
When recommending Express, the single limitation you must always state — even for fire-and-forget / high-throughput pipelines — is that Express does NOT support
.syncor.waitForTaskToken(no callbacks, no nested.syncwaits, no human-approval or job-completion waits). Also note: 5-minute max duration, no queryable execution history (CloudWatch Logs only), and at-least-once (async) / at-most-once (sync) execution — so non-idempotent work can run twice. If any of these matter, choose Standard (exactly-once, up to 1 year, full history).
JSONata is the 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:
Or per-state to migrate from JSONPath incrementally:
JSONPath is supported and is the default if QueryLanguage is omitted — existing state machines do not need to be migrated.
Field mapping (JSONPath → JSONata):
| JSONPath field | JSONata equivalent |
|---|---|
Parameters (keys use key.$) | Arguments — drop the .$ suffix and wrap each value in {% %} |
ResultSelector and OutputPath | Output (reference the raw result via $states.result) |
ResultPath | Assign (preferred) or Output |
InputPath | not needed — reference $states.input directly |
A state uses one query language, not both. Never mix JSONPath fields (
InputPath/Parameters/ResultSelector/ResultPath/OutputPath) with JSONata fields (Arguments/Output) in the same state — this is the most common migration error. Seereferences/migrating-from-jsonpath-to-jsonata.mdfor full details.
Within a single state, Assign and Output are evaluated at the same time — in parallel — both reading the same data (the state input plus the task result). They are NOT evaluated one after the other. Because they run together, a variable you set in Assign is not visible in that same state's Output: there is no ordering in which Output could observe the just-assigned value. The assigned value becomes available only to subsequent states.
So if you set a variable in Assign and reference it in the same state's Output, you get the old/undefined value — not because Output runs "before" Assign, but because both evaluate concurrently from the same snapshot. To use the value immediately, reference it in the next state (variables persist across states); to shape the current state's output from the task result, use $states.result directly in Output.
Test a single state without deploying the state machine or calling the real service using the TestState API (aws stepfunctions test-state) with --mock. A complete answer covers all four points:
--mock result MUST match the target AWS service's API response schema exactly (field names are case-sensitive). For a Lambda invoke Task that is StatusCode and Payload: --mock '{"result":"{\"StatusCode\":200,\"Payload\":{...}}"}'.--inspection-level): INFO (default — output, status, nextState), DEBUG (adds data flow: afterArguments, result, variables — use to debug JSONata/data flow), TRACE (adds raw HTTP request/response, for HTTP Task)..sync and .waitForTaskToken integrations still require a mock — for .sync, mock the polling API (e.g. DescribeExecution, not the initial call); for .waitForTaskToken, also pass --context '{"Task":{"Token":"..."}}'.See references/validation-and-testing.md for per-service mock structures and error/retry/Map/Parallel testing.
"QueryLanguage": "JSONata" at the top level for new state machines unless the user wants to use JSONPathOutput minimal — only include what the state immediately after the current state needsAssign to store variables needed in later states instead of threading it through Output$states.input to reference original state inputAssign and Output are evaluated in parallel from the state's entry data, NOT sequentially — a variable set in Assign is therefore NOT visible in the same state's Output (which still sees the pre-Assign values); the new value takes effect only in the next state.$data.nonExistentField throws States.QueryEvaluationError$states.context.Execution.Input to access the original workflow input from any state.asl.json extension when working outside the consolearn:aws:states:::lambda:invoke) over the SDK integrationStates.QueryEvaluationError — JSONata expression failed. Check for type errors, undefined fields, or out-of-range values.$ or $$ at the top level of a JSONata expression — use $states.input instead.{% %} delimiters around JSONata expressions — the string will be treated as a literal.Assign and expecting them in Output of the same state — new values only take effect in the next state.*FullAccess policies and service:* wildcards.KmsMasterKeyId) on SQS queues and SNS topics, and TLS for HTTP Tasks..waitForTaskToken token is a credential — treat it as a secret. Do not place PII, financial data, or secrets in SQS/SNS message bodies or notifications; pass a reference ID and have recipients look up details through an authorized channel.$exists() and $type(), and route invalid input to a Fail state so malformed data never reaches downstream states. Protect downstream services from bursts by setting MaxConcurrency on Map states and throttling upstream (StartExecution rate limits or EventBridge).Credentials field to assume a role in another account, include condition keys such as aws:SourceArn or aws:SourceAccount in the target role's trust policy to prevent unintended assumption.ALL or ERROR; required for Express workflows, which have no queryable execution history), enable CloudTrail to audit Step Functions API calls, and set CloudWatch Alarms on execution failures. Always encrypt the execution log group with a customer-managed KMS key, since state input/output routinely flows through execution logs.