Ravindra BagaleCourses & study guides मराठी Track your progress

What Is AWS Step Functions? Orchestrate Lambda Workflows Explained

A bank loan needs many checks in order: KYC, credit score, offer letter, then SMS. If each check is a Lambda, something must remember where we are when one step fails. That something is AWS Step Functions — a traffic policeman for your cloud workflow.

What you'll learn in this chapter

  • Why long workflows need a state machine
  • What ASL, Task, Retry, Catch, Map and Parallel mean
  • Standard vs Express workflows
  • Industries that already use Step Functions
  • Lab path, errors, FAQ and interview answers

1. Everyday example first

Why do we need this?

Swiggy order: validate cart, reserve stock, charge card, notify rider. If charge fails after stock reserve, you must release stock. Hard-coding that in one Lambda becomes spaghetti. A state machine draws the path on a board.

What is it?

AWS Step Functions runs a state machine described in Amazon States Language (ASL) JSON. Each state can call Lambda, DynamoDB, ECS, another workflow, wait, choose a branch, retry or catch errors.

Happy path (order)StartAt ValidateTask ChargeTask NotifyEnd success
Retries and Catch branches sit beside this happy path.

2. Core words

WordMeaningStreet picture
State machineThe whole flowchart you deployFull kitchen recipe
ASLJSON language of statesRecipe as JSON
TaskDo work (often Lambda ARN)One cooking step
Retry / CatchTry again or go to error pathBurnt roti: remake or call manager
Map / ParallelFan-out over a list / run branches togetherMany parcels at once
Standard / ExpressLong durable vs short high-volumeRegistered post vs bulk SMS

3. Standard vs Express

Why do we need this?

Wrong mode wastes money or loses the audit trail banks need.

What is it?

NeedPickWhy
Loan, KYC, human approval, days-long waitStandardExactly-once, 1 year max, full history
IoT click stream, 100k short pipes per secExpressAt-least-once, 5 min max, cheaper at huge volume
Need console replay for supportStandardExecution history is the support ticket

Ravindra Bagale's Tip

Start every student lab on Standard. Move to Express only when metrics prove volume.

4. Industries using it

  • Fintech (Pune/Bengaluru): KYC → bureau → offer → e-sign.
  • Healthcare: intake → insurance check → appointment SMS.
  • Ecommerce: order → fraud → warehouse → shipping label.
  • Media: upload → transcode Map state → CDN invalidate.
  • SaaS onboarding: create tenant → seed DB → welcome email.

5. How to sketch your first machine

How to do it (step by step)

  1. Write the happy path on paper with 3 to 5 boxes.
  2. Circle which box is Lambda vs wait vs choice.
  3. Add one Retry on the flaky call (payment, SMS).
  4. Add one Catch that writes failure to DynamoDB and notifies SNS.
  5. Translate to ASL JSON; start execution with a tiny input.
{
  "Comment": "Tiny charge flow",
  "StartAt": "Validate",
  "States": {
    "Validate": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:ap-south-1:123456789012:function:validate",
      "Next": "Charge"
    },
    "Charge": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:ap-south-1:123456789012:function:charge",
      "Retry": [{"ErrorEquals": ["States.TaskFailed"], "IntervalSeconds": 2, "MaxAttempts": 3}],
      "Catch": [{"ErrorEquals": ["States.ALL"], "Next": "FailNotify"}],
      "End": true
    },
    "FailNotify": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:ap-south-1:123456789012:function:fail-notify",
      "End": true
    }
  }
}

6. Mini lab: console state machine

Do this in ap-south-1 (Mumbai) unless your org forbids it. Set a budget alert first.

How to do it (step by step)

  1. Open Step Functions → Create state machine → Write your workflow in code.
  2. Paste a 2-Task ASL that calls two existing Lambdas (or the sample).
  3. Start execution with {"orderId":"lab-1"}.
  4. Open Graph view; confirm green success path.
  5. Copy the execution ARN into your notes.

Cleanup (stop billing)

  1. Delete the state machine if it is only a lab.
  2. Delete lab Lambdas if you created them only for this.

7. Common errors and fixes

Each row is a real mistake students and juniors hit. Read the fix before you panic.

Error / symptomFix
States.Runtime / invalid ASLValidate ASL in Workflow Studio or aws stepfunctions validate-state-machine-definition.
Lambda not authorizedExecution role needs lambda:InvokeFunction on that ARN.
Task timed outRaise TimeoutSeconds or fix Lambda timeout; check cold start.
Infinite Retry stormCap MaxAttempts; send to Catch.
Express used but need auditMigrate that flow to Standard.
Payload larger than 256 KBStore blob in S3; pass s3 key in state.
Map concurrency thunders LambdaSet MaxConcurrency on Map.
Wrong region ARNAll ARNs must match the state machine region.
Catch never runsErrorEquals must match; use States.ALL while learning.
Billing surpriseStandard charges per state transition — trim Wait loops.

8. Troubleshooting checklist

  1. Confirm region equals ap-south-1 (or your org region).
  2. IAM execution role attached and trusted by states.amazonaws.com.
  3. Lambda allows invoke from the role.
  4. Open failed state → error cause JSON and read it fully.
  5. Test the Lambda alone with the same payload.
  6. Check CloudWatch Logs on the Task Lambda.

9. FAQ

Q. Is Step Functions only for Lambda?

No — direct SDK integrations hit many AWS APIs without Lambda glue.

Q. Step Functions vs SQS?

SQS is a queue; Step Functions is an orchestrator with branches and history.

Q. Can I wait 30 days?

Standard Wait state can wait up to one year.

Q. Does Express support all states?

Most, but history and exactly-once differ — read docs before migrating.

Q. How do I unit test ASL?

Prefer contract tests on Lambdas plus small integration executions.

10. Interview Q&A

Q. What is a state machine in AWS?

A deployed ASL flowchart Step Functions executes with retries and branches.

Q. Standard vs Express?

Standard: long, exactly-once, full history. Express: short, high volume, cheaper.

Q. Why Catch and Retry?

Retry handles blips; Catch handles poison with a defined failure path.

Q. Map state use case?

Fan-out the same work over an array (resize 500 images).

Q. How do you pass large files?

S3 object key in the JSON; never the whole file.

Q. Idempotency tip?

Make Task Lambdas idempotent; use execution name or business key.

11. Tips in English, Marathi and Hindi

Ravindra Bagale's Tip (EN)

Draw the flowchart before you open the console. Cheap paper beats expensive failed executions.

Ravindra Bagale's Tip (MR)

आधी कागदावर flowchart. स्वस्त कागद > महाग failed executions.

Tip (HI)

पहले कागज़ पर flowchart बनाओ — सस्ता कागज़ महंगे failed execution से बेहतर है।

Try at home

  1. Rewrite the Swiggy path as 4 boxes with one Catch.
  2. In console, open a sample project and press Start execution.
  3. List three workflows at your job or college that need orchestration.

In short

  1. Step Functions = state machine for AWS workflows.
  2. ASL JSON describes Task, Choice, Wait, Map, Parallel, Retry, Catch.
  3. Standard for durable business flows; Express for short high-volume.
  4. Always design failure paths and cleanup lab resources.

Revision, interview and comparison cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Revision card: What is AWS Step Functions?. A bank loan app needs many Lambdas in order: score → fraud → approve. Hand-written chaining is hard to watch and retry. Step Functions is a managed workflow: you draw or write states that call Lambda, wait, choose, and retry. Create a state machine (ASL JSON or Workflow Studio) → grant it invoke rights → start an execution with input JSON. Console graph shows each step green/red; failed step can retry without redoing the whole loan flow.
Revision card: What is AWS Step Functions? · Download PNG · Open card page
Revision card: Task, Choice, Wait, Parallel. Wrong state type makes the workflow hang or skip business rules. Task = do work (Lambda). Choice = if/else. Wait = pause. Parallel = run branches together. Fail/Succeed end the run. Map a happy path with Task + Choice; add Wait for human or timer; use Parallel only when branches are independent. Choice on $.status == APPROVED goes to disburse Task; else goes to reject Succeed.
Revision card: Task, Choice, Wait, Parallel · Download PNG · Open card page
Revision card: Retry and Catch. A flaky payment API should not fail the whole order on the first timeout. Retry repeats a Task on named errors with backoff. Catch routes failure to a cleanup or alert state. Add Retry for States.TaskFailed and Lambda.ServiceException; Catch unknown errors to a notify Fail state. Execution history shows three retries then Catch path when the API stayed down.
Revision card: Retry and Catch · Download PNG · Open card page
Revision card: Standard vs Express. IoT click streams need huge volume; loan approvals need long waits and full history. Standard: long-running, exactly-once, full history (up to 1 year). Express: high-rate, at-least-once, cheaper, short runs. Use Standard for orders and approvals. Use Express for high-volume ETL-like steps under five minutes. A checkout that waits for payment webhook fits Standard; a log enricher at 10k/sec fits Express.
Revision card: Standard vs Express · Download PNG · Open card page
Revision card: IAM for the state machine. Execution fails with AccessDenied when the role cannot invoke Lambda or write logs. The state machine role needs lambda:InvokeFunction on target functions and permission for any service integration you call. Create a role trusted by states.amazonaws.com; attach least-privilege policy for each Task resource ARN. After fixing the role, a new execution reaches the Lambda Task instead of failing at schedule time.
Revision card: IAM for the state machine · Download PNG · Open card page
Comparison: Standard workflow vs Express workflow. Standard workflow: Long runs, exactly-once, full history (up to 1 year). Express workflow: High-rate, at-least-once, short, cheaper.
Comparison: Standard workflow vs Express workflow · Download PNG · Open card page
Comparison: Task state vs Map state. Task state: Calls one resource once per entry (often Lambda). Map state: Runs the same processor over each array item.
Comparison: Task state vs Map state · Download PNG · Open card page
Interview card: Step Functions vs code orchestration?. Step Functions is a managed state machine for multi-step workflows with visual history, retries, and service integrations. You get retries/Catch, timeouts, and audit without maintaining a custom orchestrator server. Loan approval with Lambda tasks and Choice on score is a classic Step Functions fit.
Interview card: Step Functions vs code orchestration? · Download PNG · Open card page
Interview card: Standard or Express workflows?. Standard: long runs, exactly-once, rich history. Express: high volume, short, cheaper, at-least-once. Pick based on duration, volume, and whether you need per-step history for audits. Human approval wait → Standard. Enrich millions of click events → Express.
Interview card: Standard or Express workflows? · Download PNG · Open card page
Interview card: How do you keep tasks idempotent?. Idempotent means retrying the same Task does not double-charge or double-insert. Use business keys, conditional writes, and Step Functions Retry only on safe errors. Payment Task keys on orderId so a retry after timeout does not bill twice.
Interview card: How do you keep tasks idempotent? · Download PNG · Open card page
Interview card: When do you use Map?. Map runs the same processing over an array of items, with concurrency limits. Use it for fan-out over orders/files; prefer Parallel only for fixed named branches. Process 500 invoice IDs with MaxConcurrency 10 so Lambda is not flooded.
Interview card: When do you use Map? · Download PNG · Open card page

More cards: Ravi Sir's Cards.

Practice Tasks

About this scenario

Maple Leaf Books is a bookselling business in Toronto. Emily Tremblay looks after its IT and cloud work. They count money in CAD and run their AWS resources in the ca-central-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 16

Easy List state machines

Why: See which workflows exist.

What to do: List state machines in ca-central-1.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Describe a state machine

Why: Check definition and role ARN.

What to do: Describe state machine arn:aws:states:ca-central-1:102932412000:stateMachine:mapleleafbooks-order.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Delete a state machine

Why: Stop lab billing for unused machines.

What to do: Delete state machine arn:aws:states:ca-central-1:102932412000:stateMachine:mapleleafbooks-lab.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy List executions

Why: See running and failed runs.

What to do: List executions for arn:aws:states:ca-central-1:102932412000:stateMachine:mapleleafbooks-order.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Standard max duration (years)

Why: Know the durable limit.

What to do: How many years can a Standard workflow run at most?

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Express max minutes

Why: Express is short.

What to do: Express workflows max duration in minutes?

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Start an execution

Why: Run the workflow with input.

What to do: Start execution on arn:aws:states:ca-central-1:102932412000:stateMachine:mapleleafbooks-order named run-1 with input file://input.json.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Get execution history

Why: Debug which state failed.

What to do: Get history for execution arn:aws:states:ca-central-1:102932412000:execution:mapleleafbooks-order:run-1.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Stop an execution

Why: Cancel a stuck run.

What to do: Stop execution arn:aws:states:ca-central-1:102932412000:execution:mapleleafbooks-order:run-1.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Validate a definition

Why: Catch ASL errors early.

What to do: Validate the state machine definition in asl.json.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Trust policy for Step Functions

Why: Who may assume the role.

What to do: Trust policy that lets states.amazonaws.com assume the role.

How:
  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Medium Allow SFN to invoke one Lambda

Why: Least privilege for Task states.

What to do: Allow lambda:InvokeFunction on arn:aws:lambda:ca-central-1:102932412000:function:mapleleafbooks-charge only.

How:
  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Medium Payload limit KB

Why: Know when to use S3.

What to do: Max state payload size often cited in KB?

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Create a state machine

Why: Deploy ASL from a file.

What to do: Create state machine mapleleafbooks-order of type STANDARD with role arn:aws:iam::102932412000:role/mapleleafbooks-sfn and definition file://asl.json.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Hard ASL: Validate then Charge

Why: State machines need a clear StartAt path.

What to do: Write ASL JSON: StartAt Validate; Validate Task Resource arn:aws:lambda:ap-south-1:123456789012:function:validate Next Charge; Charge Task Resource arn:aws:lambda:ap-south-1:123456789012:function:charge End true.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Hard ASL with Retry

Why: Retries soften flaky payments.

What to do: ASL: StartAt Pay; Pay Task Resource arn:aws:lambda:ap-south-1:123456789012:function:pay with Retry MaxAttempts 3 on States.TaskFailed and End true.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.