What is AWS Lambda and how does serverless computing work?
Understand AWS Lambda and serverless computing: event-driven functions, automatic scaling, per-millisecond billing, cold starts, and when to use it.
Expected Interview Answer
AWS Lambda is a serverless compute service that runs your code in response to events without you provisioning or managing servers, automatically scaling and charging only for the compute time your functions actually use.
You upload a function, define a trigger (such as an API Gateway request, S3 upload, or queue message), and Lambda runs it in a managed, ephemeral environment. It handles provisioning, patching, scaling, and availability. Serverless means the cloud provider owns the infrastructure entirely; you think in terms of functions and events, paying per invocation and per millisecond of execution rather than for idle capacity.
- No server management or capacity planning
- Automatic, near-instant horizontal scaling
- Pay only for execution time (per-millisecond billing)
- Event-driven integration with many AWS services
- Faster deployment of small, focused units of code
AI Mentor Explanation
Lambda is like a specialist substitute fielder who only walks onto the pitch for a single catch and leaves the moment it is taken. You never pay him to sit in the pavilion; he appears exactly when a ball is hit his way and you are billed only for those few seconds of action.
Step-by-Step Explanation
Step 1
Write the function
Author a handler in a supported runtime (Node.js, Python, Java, Go, etc.) that receives an event object and returns a result.
Step 2
Configure a trigger
Wire an event source such as API Gateway, S3, DynamoDB Streams, or SQS to invoke the function.
Step 3
Set memory and timeout
Allocate memory (which also scales CPU) and a maximum execution timeout appropriate to the workload.
Step 4
Deploy and invoke
Upload the code/package; Lambda provisions an execution environment on demand when an event arrives.
Step 5
Scale and monitor
Lambda spins up concurrent environments automatically under load; observe metrics and logs in CloudWatch.
What Interviewer Expects
- Definition of serverless and the shared-responsibility shift
- Event-driven invocation model
- Per-invocation, per-millisecond billing understanding
- Awareness of cold starts and concurrency
- Knowledge of common triggers and limits (timeout, memory)
Common Mistakes
- Claiming serverless means there are literally no servers
- Ignoring cold starts and their latency impact
- Trying to run long-lived or stateful processes in Lambda
- Forgetting the maximum execution timeout limit
Best Answer (HR Friendly)
“AWS Lambda lets you run code without managing any servers. Your code runs automatically whenever something triggers it, scales on its own, and you only pay for the exact time it runs, so there is no cost when nothing is happening.”
Code Example
Resources:
HelloFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs20.x
MemorySize: 256
Timeout: 10
Events:
Api:
Type: Api
Properties:
Path: /hello
Method: getFollow-up Questions
- What is a cold start and how do you mitigate it?
- How does Lambda concurrency and throttling work?
- When would Lambda be a poor fit for a workload?
- How is Lambda pricing calculated?
MCQ Practice
1. How is AWS Lambda primarily billed?
Lambda charges for the number of requests and the compute duration (rounded to the millisecond) scaled by allocated memory.
2. Which of these is a valid Lambda event source?
S3 can trigger a Lambda on events like object creation; the others are not Lambda event sources.
3. A 'cold start' in Lambda refers to:
A cold start is the extra latency incurred when Lambda must initialize a fresh execution environment before running your handler.
Flash Cards
What is AWS Lambda? — A serverless compute service that runs code in response to events without managing servers, scaling automatically.
How is Lambda billed? — Per request plus execution duration in milliseconds, scaled by allocated memory. No charge when idle.
What is a cold start? — The added latency when Lambda initializes a new execution environment for an invocation.
Lambda max timeout — A Lambda function can run for up to 15 minutes per invocation.