AWS Serverless Stack
Functions, gateways, queues and state machines
API Gateway + Lambda + DynamoDB + S3 + SQS is the canonical AWS serverless stack. Events in, code runs, state is managed — you pay per use and scale with zero servers.
What you will learn
- Assemble an API Gateway + Lambda + DynamoDB stack
- Explain event-driven integration with SQS/SNS/EventBridge
- Manage Lambda cold starts, concurrency and permissions
API Gateway fronts HTTP endpoints; Lambda runs the logic; DynamoDB/S3 store state; SQS/SNS/EventBridge move events; Step Functions orchestrate multi-step flows. Everything scales automatically and bills per use.
What is this?
AWS Lambda runs your code at up to 10GB of memory and 15-minute limits, handling concurrency and scaling. API Gateway exposes REST/HTTP/WebSocket APIs with authentication and throttling. SQS (queues), SNS (fan-out topics) and EventBridge (event bus + rules) move events between services. Step Functions orchestrates state machines for multi-step, stateful workflows. S3/ DynamoDB provide storage. This stack turns a backend into a set of small leased functions.
Why do you need it?
- Serverless collapses ops: no servers to patch, no capacity planning, per-request billing.
- Event-driven glue (SQS/SNS/EventBridge) makes systems resilient to spikes by buffering.
- Step Functions replaces fragile cron+retry loops with auditable state machines.
- It is the common denominator interviewers expect you to sketch on a whiteboard.
Mental model
A restaurant kitchen with a ticket rail
AWS serverless
Tickets (events/requests) arrive on the rail; chefs (Lambda) grab one, cook, and pass the result. The rail (SQS) absorbs rushes; the manager (Step Functions) sequences multi-course meals. No one owns a stove — the kitchen scales on demand.
How it works
- API Gateway authenticates, throttles and routes a request to a Lambda via an IAM-based integration.
- Lambda runs in a sandbox with its own memory/timeout/concurrency; you pay per request and GB-seconds.
- SQS buffers work for asynchronous consumers; DLQs catch poisoned messages for repair.
- SNS/EventBridge fan out one event to many subscribers with filtering rules.
- Step Functions coordinates stateful flows with retries, timeouts and human-approval steps.
- Permissions are role-based: API Gateway assumes an execution role to invoke Lambda; Lambda assumes roles to reach DynamoDB/S3.
The canonical serverless payment/order flow.
In production
- A checkout endpoint validates via Lambda, records in DynamoDB, and enqueues an invoice job to SQS consumed by a worker Lambda.
- EventBridge rules route 'order.created' to audit, analytics and notification subscribers independently.
- Step Functions runs a 12-step refund flow with retries, compensating steps and a log for every transition.
Best practices
- Keep functions small, stateless and idempotent; let storage own the state.
- Use queues for anything that doesn't need a synchronous answer, with a DLQ.
- Set Lambda reserved concurrency to protect downstream databases from fan-out.
- Enable X-Ray/structured logging and tag functions for cost attribution.
Common mistakes
- Putting VPC-attached Lambdas without NAT/endpoints, breaking internet access.
- Synchronous calls between services that should be queued — a spike becomes a timeout storm.
- Fat functions (500MB zips, cold npm trees) inflating cold starts.
- Forgetting idempotency: retries replay side effects unless you dedupe.
Common issues
API Gateway returns 504 repeatedlyLambda integration timed out (sync integration waits) or function over memory
Increase Lambda timeout/memory or go async via SQS for long-running work.
Lambda can't reach an RDS instanceFunction in VPC lacks route to the DB SG or VPC placement
Attach the function to the same VPC/subnets as RDS and allow the DB SG to accept from Lambda SG.
Messages reprocessed twice after crashSQS at-least-once semantics and non-idempotent handler
Make consumers idempotent (dedupe key in DynamoDB) before relying on retries.
Debugging tips
- Check CloudWatch Logs group per function and the X-Ray trace for Init vs runtime time.
- For throttled invocations, check concurrency limits and reserved concurrency rather than code.
- SQS messages stuck? Inspect the DLQ and the message attributes/handlers.
- API returns 429/403? Look at usage plans, authorizers and the execution role.
Interview checkpoint
Hands-on lab
- Create and deploy a Lambda function
- Invoke it directly and confirm the result
- Identify the IAM execution role and log group created
Deploy a Hello-World Lambda End-to-End
30 min · intermediate
Quick quiz
Which service lets Lambda process messages reliably when downstream is slow?
A Lambda in a VPC can always reach the public internet by default.