On this page
On this page
- What Is Lambda
- Execution Model and Cold Starts
- Invocation Types
- Concurrency Model
- Versions and Aliases
- Event Source Mappings (Poll-Based Sources)
- Asynchronous Destinations
- VPC Integration
- Lambda@Edge and CloudFront Functions
- Execution Role vs. Resource-Based Policy
- Layers and Container Images
- Lambda Limits
- Key CloudWatch Metrics
- Key Exam Scenarios
- CloudWatch Integration
- Automatically Published (AWS/Lambda namespace โ per invocation)
- Requires Setup
Lambda
Lambda lets you run code without managing servers. You write a function, upload it to Lambda, and AWS handles everything else โ the servers, the operating system, the scaling, the availability. You pay only for the time your code is actually executing, rounded to the nearest millisecond.
The Core Idea
Traditional servers run all the time, waiting for work. Lambda flips this: your code sleeps until something triggers it, runs, and goes back to sleep. That "something" can be an HTTP request arriving at API Gateway, a file landing in S3, a message appearing in SQS, a scheduled timer, or dozens of other AWS events. Lambda integrates natively with most AWS services as a reaction engine.
Why It Matters
Lambda removes an entire category of operational work. No servers to patch, no capacity to plan, no idle time to pay for. If your function is called 10 times a day, you pay for 10 executions. If traffic spikes to 10,000 simultaneous requests, Lambda scales automatically โ no configuration needed.
This makes Lambda ideal for event-driven workloads: image processing when a photo is uploaded, sending a notification when an order is placed, transforming records as they stream through Kinesis, or running a scheduled report every night.
How a Function Works
You write a handler โ a function that receives an event object and a context object and returns a result. The event contains the data from whatever triggered the function (the HTTP request body, the S3 object key, the SQS message, etc.).
def handler(event, context):
name = event.get("name", "World")
return {"statusCode": 200, "body": f"Hello, {name}!"}
Lambda runs this function in an execution environment โ a small, isolated container managed by AWS. The first time your function is invoked, Lambda initializes a fresh environment (a "cold start"). If another request comes in shortly after, Lambda reuses the same environment (a "warm start"), skipping initialization. Code outside the handler runs only on cold starts, so you can cache database connections and configuration there.
Key Limits to Know
Lambda functions can run for a maximum of 15 minutes per invocation. They
are stateless โ don't rely on local files persisting between invocations.
The only writable local storage is /tmp (up to 10 GB), but it's temporary and
may not be shared across invocations.
For work that takes longer than 15 minutes, or that needs persistent state or a full OS environment, use ECS Fargate or EC2 instead.
/tmp scratch disk. If a job outgrows any of the three, it has outgrown Lambda โ move it to ECS Fargate or EC2.