What is AWS Lambda?
Learn what AWS Lambda is, how event-driven serverless compute works, cold starts, pricing, and how to explain Lambda clearly in an AWS interview.
Expected Interview Answer
AWS Lambda is a serverless, event-driven compute service that runs your code in response to triggers without you provisioning or managing any servers, billing only for the compute time actually consumed during execution.
You upload a function's code, choose a runtime and memory allocation, and Lambda handles provisioning, patching, and scaling the underlying compute automatically, including running many concurrent invocations in parallel. Functions are invoked by event sources such as API Gateway requests, S3 object uploads, DynamoDB streams, or scheduled EventBridge rules, and each invocation runs in an isolated execution environment with a configurable timeout. Because compute only exists during invocation, cold starts can add latency to the first request after idle periods, which provisioned concurrency can mitigate. Lambda is well suited to short-lived, event-driven, or bursty workloads, while long-running or highly stateful processes are usually better served by EC2 or containers.
- No server provisioning, patching, or capacity planning
- Automatic scaling to match concurrent event volume
- Pay only for actual execution time, down to the millisecond
- Tight integration with dozens of AWS event sources
- Faster iteration since only function code is deployed, not infrastructure
AI Mentor Explanation
Lambda is like an on-call substitute fielder who only steps onto the pitch the instant a ball heads to a gap, then leaves immediately after making the play. You never pay a substitute for standing around, only for the seconds they were active, and dozens can appear at once if several balls need covering simultaneously.
Step-by-Step Explanation
Step 1
Write and package function code
Author a handler function in a supported runtime (Node.js, Python, Java, etc.) and package it as a deployment artifact.
Step 2
Configure trigger and permissions
Attach an event source (API Gateway, S3, DynamoDB Streams, EventBridge) and an execution role via IAM.
Step 3
Lambda provisions execution environment
On invocation, Lambda spins up an isolated environment to run the handler, reusing warm environments when possible.
Step 4
Function executes and returns
The handler runs, does its work, and returns a response or completes side effects within the configured timeout.
Step 5
Lambda scales and bills per invocation
Concurrent invocations scale automatically; billing is based on execution duration and memory allocated.
What Interviewer Expects
- Explains Lambda as serverless, event-driven compute with automatic scaling
- Knows billing is based on invocation duration and memory, not idle time
- Can name common event sources (API Gateway, S3, DynamoDB Streams, EventBridge)
- Understands cold starts and how provisioned concurrency addresses them
- Knows when Lambda is a poor fit (long-running, highly stateful workloads)
Common Mistakes
- Claiming Lambda has no infrastructure at all rather than infrastructure AWS manages
- Forgetting about cold start latency for infrequently invoked functions
- Assuming Lambda functions can run indefinitely without a timeout limit
- Using Lambda for long-running, stateful workloads better suited to EC2 or containers
Best Answer (HR Friendly)
“AWS Lambda lets developers run small pieces of code automatically in response to events, like a file upload or an API call, without managing any servers. The company only pays for the exact time the code runs, which makes it efficient and cost-effective for many automated tasks.”
Code Example
import json
def handler(event, context):
for record in event["Records"]:
bucket = record["s3"]["bucket"]["name"]
key = record["s3"]["object"]["key"]
print(f"New object uploaded: s3://{bucket}/{key}")
return {"statusCode": 200, "body": json.dumps("Processed")}aws lambda create-function \
--function-name process-upload \
--runtime python3.12 \
--handler app.handler \
--role arn:aws:iam::123456789012:role/lambda-exec-role \
--zip-file fileb://function.zip
aws lambda invoke --function-name process-upload out.json
# {"StatusCode": 200, "ExecutedVersion": "$LATEST"}Follow-up Questions
- What is a cold start and how can you reduce its impact?
- How does Lambda pricing work in terms of duration and memory?
- What event sources can trigger a Lambda function?
- How does Lambda handle concurrency and throttling?
- When would you choose Lambda over containers on ECS/Fargate?
MCQ Practice
1. How is AWS Lambda primarily billed?
Lambda bills based on the number of invocations plus the duration and memory configured for each execution.
2. What is a 'cold start' in AWS Lambda?
A cold start occurs when Lambda must provision a fresh execution environment, adding latency compared to reusing a warm one.
3. Which workload is generally a poor fit for AWS Lambda?
Lambda has execution timeout limits and is optimized for short, event-driven work; long stateful processes suit EC2 or containers better.
Flash Cards
What is AWS Lambda? — A serverless, event-driven compute service that runs code in response to triggers without managing servers.
How is Lambda billed? — Based on invocation count, execution duration, and memory allocated -- not idle time.
What is a cold start? — The latency added when Lambda initializes a fresh execution environment for an idle function.
Name three common Lambda triggers. — API Gateway requests, S3 object events, and DynamoDB Streams (also EventBridge schedules).