Skip to content
VirtualLP Virtual Learning Platform

Orchestrating Workflows with AWS Step Functions

12 min read Topic 15 of 30 1 hands-on lab

When a business process has several steps – validate, charge, reserve stock, notify – coding the order, retries and error handling inside one Lambda becomes messy. AWS Step Functions coordinates the steps as a visual state machine and keeps the state of every execution.

stateDiagram-v2
    [*] --> ValidateOrder
    ValidateOrder --> IsValid
    IsValid --> ChargePayment: valid
    IsValid --> RejectOrder: invalid
    ChargePayment --> Parallel
    state Parallel {
        ReserveStock
        --
        SendConfirmation
    }
    Parallel --> [*]
    RejectOrder --> [*]

Amazon States Language (ASL)

{
  "StartAt": "ValidateOrder",
  "States": {
    "ValidateOrder": { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke",
      "Parameters": { "FunctionName": "validate-order", "Payload.$": "$" },
      "Retry": [{ "ErrorEquals": ["Lambda.TooManyRequestsException"], "IntervalSeconds": 2, "MaxAttempts": 3, "BackoffRate": 2 }],
      "Catch": [{ "ErrorEquals": ["States.ALL"], "Next": "RejectOrder" }],
      "Next": "IsValid" },
    "IsValid": { "Type": "Choice",
      "Choices": [{ "Variable": "$.Payload.valid", "BooleanEquals": true, "Next": "ChargePayment" }],
      "Default": "RejectOrder" },
    "ChargePayment": { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "End": true },
    "RejectOrder": { "Type": "Fail", "Error": "InvalidOrder" }
  }
}
State Purpose
Task Do work – Lambda, or call 200+ AWS services directly (DynamoDB, SQS, SNS, ECS, Bedrock…)
Choice Branch on input values
Parallel Run branches at the same time
Map Run the same steps for each item of an array (distributed Map for millions of S3 objects)
Wait Pause for seconds or until a timestamp
Pass / Succeed / Fail Shape data, finish successfully or with an error

Error handling

  • Retry with interval, max attempts and exponential backoff per error type.
  • Catch routes failures to a compensating step (refund, notify).
  • Every execution has a full history – each state’s input, output and errors.

Standard vs Express

Standard Express
Duration Up to 1 year Up to 5 minutes
Semantics Exactly-once At-least-once
Price Per state transition Per execution duration and memory
Use Long business processes, human approval High-volume event processing

Patterns

  • Request/response, run a job (.sync) – wait for ECS/Glue/Batch jobs to finish.
  • Wait for callback (.waitForTaskToken) – pause until a human approves via e-mail/app.
  • Saga – compensate earlier steps when a later one fails.
  • Orchestrate GenAI pipelines: prompt-chain several Bedrock calls with checks between them.
Key point

Use Step Functions for orchestration (a defined sequence with retries and state) and EventBridge/SNS for choreography (independent services reacting to events).

Practise it

Virtual lab · Amazon Web Services · 40 min

Orchestrate an order workflow with AWS Step Functions

Write a state machine in the Amazon States Language that validates an order, branches on the amount, charges payment with automatic retries, catches a declined card and ships the order – then trace every execution in the graph and event history.

Open lab

Quick revision

  1. A state machine is defined in Amazon States Language (JSON).
  2. Task, Choice, Parallel, Map, Wait, Pass, Succeed, Fail.
  3. Retry and Catch give declarative error handling.
  4. Standard = long and exactly-once; Express = short and high-volume.
  5. Callback tokens enable human approval steps.

Practise this topic

Hands-on virtual lab

Apply what you just read in a realistic, guided simulation. Free with a verified account.

Create a free account to track your progress and unlock virtual labs.