Part 6 of the Serverless series.

Some processes have several steps that must happen in order, with retries, branches, waits and compensation when something fails: processing an order, onboarding a user, running a data pipeline, or generating and checking AI output. AWS Step Functions runs those processes as state machines, so the flow is visible, auditable and resilient instead of buried in code.

The mental model

A state machine is defined in JSON (the Amazon States Language) or drawn in Workflow Studio. Each state does one thing:

  • Task: call a service (a Lambda function, DynamoDB, SQS, Bedrock, ECS…)
  • Choice: branch on the data
  • Parallel: run branches at the same time
  • Map: run the same steps for every item in a list (Distributed Map handles millions of items, such as every object in an S3 prefix)
  • Wait: pause for a duration or until a time
  • Succeed / Fail

Every execution is recorded, and the console shows exactly which step ran, with what input and output, and where it failed.

Standard vs Express

Standard Express
Max duration Up to a year 5 minutes
Execution semantics Exactly-once per step At-least-once (async) or at-most-once (sync)
Pricing Per state transition Per request and duration
Use for Long-running, auditable business processes High-volume, short event processing

Call services directly

Step Functions can call more than 200 AWS services directly through SDK integrations. Many workflows need far fewer Lambda functions than you’d expect: write to DynamoDB, publish to EventBridge or send an SQS message straight from the state machine. Use JSONata expressions to transform data between steps without code.

Error handling

Every Task can declare Retry (with exponential backoff) and Catch (route to a fallback state) rules:

"ChargeCard": {
  "Type": "Task",
  "Resource": "arn:aws:states:::lambda:invoke",
  "Arguments": { "FunctionName": "charge-card", "Payload": "{% $states.input %}" },
  "Retry": [{ "ErrorEquals": ["States.TaskFailed"], "MaxAttempts": 3, "BackoffRate": 2 }],
  "Catch": [{ "ErrorEquals": ["States.ALL"], "Next": "ReleaseStock" }],
  "Next": "ShipOrder"
}

That Catch is the saga pattern: when a later step fails, run compensating steps to undo the earlier ones.

Waiting for a person or another system

The wait for callback pattern (.waitForTaskToken) pauses a Standard workflow until something calls SendTaskSuccess with a token: a manager clicking “approve” in an email, or an external system finishing a job. You pay nothing while it waits, even for days.

Step Functions or Lambda durable functions?

Lambda durable functions let you write multi-step, long-running workflows as ordinary code, with checkpointed steps and waits. Roughly:

  • Choose Step Functions when you want a visual workflow, direct integrations with many AWS services, or massive parallel processing with Distributed Map.
  • Choose durable functions when the workflow is mostly your own logic and your team would rather read and test it as code in one function.

Hands-on: an order workflow

Build a Standard workflow in Workflow Studio:

  1. DynamoDB PutItem: record the order as PENDING.
  2. Lambda: “charge” the card (have it fail randomly), with a Retry.
  3. Choice on the result: on success, DynamoDB UpdateItem to PAID and EventBridge PutEvents with OrderPaid; on failure, update to FAILED.

Start several executions and use the execution graph to follow each one.

Gotchas

  • Payload limit. State input and output are limited (256 KB). Pass references to S3 or DynamoDB, not large documents.
  • Standard workflows are billed per transition. Very chatty, high-volume flows belong in Express.
  • Make tasks idempotent. Retries mean a step can run more than once.

Next: AppSync GraphQL: one API for many data sources.

← Series overview