I always go Lambda-first. Except for this.


AWS FOR THE REAL WORLD
⏱️
Reading time: 8 minutes
🎯
Main Learning: How to pause Step Function workflows for human approval using the callback pattern
📝

Hey Reader 👋🏽

I've used this pattern in almost every project I've built.

Whenever you need a human in the loop - approvals, reviews, manual checks - and you still want to see what's happening, Step Functions are perfect.

Lambda is my go-to for almost everything.

  • APIs
  • S3 triggers
  • event consumers

But for workflows where someone needs to approve or reject something? I always reach for Step Functions. In this issue, I'll show you the "Wait for Callback" pattern. We'll build a content moderation system where admins approve or reject blog posts before they go live. Rather watch a video? I've recorded one for you.

video preview

Rather reading it? Check out the deep dive 👇🏽

Step Functions Callback Pattern

📚 This Week's Deep Dive

The Problem with Human-in-the-Loop Workflows

Picture a blogging platform. Users submit posts. Admins review them before they go live.

The tricky part: these happen at different times. A user submits at 9am. An admin reviews at 3pm. How do you connect these?

With Lambda alone, you'd need polling. Save state to a database. Run a CRON job. Check every few minutes if someone approved. It works, but it's ugly.

Step Functions handle this elegantly with the "Wait for Callback" pattern.

How It Works

  1. User submits a blog post through API Gateway
  2. Step Function starts and invokes a Lambda function
  3. Lambda saves the content AND a task token to DynamoDB
  4. Step Function pauses - it waits for that token to come back
  5. Admin sees pending posts in a dashboard, clicks approve or reject
  6. Another API call sends the task token back to Step Functions
  7. Step Function resumes and handles the result

The key is that task token. It's like a parking ticket. The workflow hands it out, parks itself, and waits until someone brings the ticket back.

Things to Watch Out For

Token expiration: Tokens can be valid up to one year. We set ours to 7 days.

Token security: Anyone with the token can resume your workflow. Keep them private.

Standard only: This pattern only works with Standard Step Functions (billed per state transition), not Express.

Error handling: A rejected post isn't a failure - it's a valid outcome. Design your error handling accordingly.

Why Not Just Use Lambda?

You could. Save everything to DynamoDB. Poll with EventBridge. Check if approved.

But you lose visibility. Step Functions show you a visual graph of exactly what happened. When something goes wrong, you see the exact state. Non-technical people can look at the diagram and understand the flow.

For approval workflows, that visibility is worth it.

That's it for this week!

The callback pattern is one of those things that once you know it, you'll use it everywhere. Approval workflows, manual QA checks, payment confirmations - anywhere a human needs to be in the loop.

Clone the repo, deploy it to your account, and break things.

See you soon!

Sandro & Tobi

AWS for the Real World

We teach AWS for the real world - not for certifications. Join more than 10,500 developers learning how to build real-world applications on AWS.

Read more from AWS for the Real World

AWS FOR THE REAL WORLD ⏱️ Reading time: 5 minutes 🎯 Main Learning: How to make Claude write production-ready Terraform instead of technical debt 🎬 Watch on YouTube 📝 Blog Post 💻 GitHub Repository Hey Reader 👋🏽 We've been heads-down the past weeks. Preparing the live AMA workshops from Black Friday (sorry for the delay!) and recording new YouTube videos. It's been a lot of fun. Speaking of videos - this week Tobi recorded one you'll want to watch. Here's the problem: LLMs want to close the...

AWS FOR THE REAL WORLD ⏱️ Reading time: 8 minutes 🎯 Main Learning: 5 practical techniques to cut Lambda costs (memory, timeouts, ARM, batching, caching) 📝 Blog Post 🎬 Watch on YouTube Hey Reader 👋🏽 Lambda bills can sneak up on you. One function is often not expensive. But then you scale it up and 💥 it costs you $5,000. Sounds familiar? We had this exact problem with our Shopify fraud detection app. Orders coming in via EventBridge, each triggering its own Lambda.And the bill was $150/month...

AWS FOR THE REAL WORLD ⏱️ Reading time: 8 minutes 🎯 Main Learning: Generate AWS architecture diagrams using AI with Kiro and MCP servers - skip the hours of dragging boxes in Lucidchart. 📝 Blog Post 🎬 Watch on YouTube Hey Reader 👋🏽 Big news: We launched our YouTube channel! 🎬 We've published 7 videos so far and are almost at 800 subscribers. Our goal is to keep a weekly rhythm, so expect fresh content every week. If you haven't subscribed yet, here's the link. No exciting AWS news this week....