What Is AWS Lambda and How Does Serverless Work?
How AWS Lambda runs code: execution environment lifecycle, cold starts, scaling, invocation types, key quotas and when serverless is the wrong fit.
AWS Lambda is a serverless compute service that runs your code in response to events without you managing servers. You upload a function, connect it to a trigger such as an API request, an S3 upload or a queue message, and Lambda starts isolated execution environments, scales them with demand and bills for the time your code runs.
This guide explains how Lambda works under the hood, how serverless architecture fits together around it, what the main limits are and when another compute option is a better choice. It is the starting point for our Lambda series, which goes deeper into triggers, cold starts and monitoring with CloudWatch Logs.
Key takeaways
- A Lambda function is code plus configuration (runtime, memory, timeout, permissions). Lambda runs it inside an execution environment that goes through Init, Invoke and Shutdown phases.
- Serverless architecture combines Lambda with managed services such as API Gateway, S3, DynamoDB, SQS, SNS and EventBridge, so no team manages servers directly.
- A standard function can run for up to 15 minutes (900 seconds) and use 128 MB to 10,240 MB of memory. CPU scales with memory, reaching about one vCPU at 1,769 MB.
- Synchronous invocations accept up to 6 MB for the request and 6 MB for the response; asynchronous invocations accept up to 1 MB.
- The default regional concurrency quota is 1,000 concurrent executions, which can be raised. New accounts may start with lower quotas.
- Cold starts happen when Lambda creates a new execution environment. AWS says they typically occur in under 1% of invocations; provisioned concurrency and SnapStart reduce them.
What serverless actually means
Serverless does not mean there are no servers. It means you do not provision, patch or scale them. AWS runs the underlying fleet, and you work with higher-level building blocks: functions, queues, tables, buckets and APIs. You pay for what you use rather than for idle capacity, and scaling is handled by the platform.
For a DevOps engineer, the shift is in what you own. With EC2 you own the operating system, the runtime, patching, scaling policies and capacity planning. With Lambda you own the function code, its dependencies, its configuration and its permissions. AWS owns the rest. That reduces operational work, but it also introduces new constraints, which we cover below.
How a Lambda function is built
The AWS Lambda runtimes page now calls standard functions "Lambda Event Functions" (previously known as Lambda functions), to tell them apart from newer options such as Lambda Web Functions. This post covers the standard, event-driven kind.
A Lambda function has three parts:
- Code. A handler function in a managed runtime (Node.js, Python, Java, .NET or Ruby, each pinned by an identifier such as
python3.14), or an OS-only runtime for languages like Go and Rust. You deploy it as a .zip archive or as a container image. - Configuration. Memory size, timeout, environment variables, layers, VPC settings and concurrency settings.
- Permissions. An execution role (an IAM role) that defines what the function can access, plus a resource-based policy that defines who can invoke it.
Here is a minimal Python handler. Lambda passes in an event (the trigger's data) and a context object (runtime information such as the request ID and remaining time).
import json
import boto3
s3 = boto3.client("s3") # created once per execution environment
def lambda_handler(event, context):
records = event.get("Records", [])
for record in records:
bucket = record["s3"]["bucket"]["name"]
key = record["s3"]["object"]["key"]
print(f"New object: s3://{bucket}/{key}")
return {"statusCode": 200, "body": json.dumps({"processed": len(records)})}
Notice that the S3 client is created outside the handler. That code runs once when the execution environment initialises, and later invocations in the same environment reuse it. AWS recommends this pattern for SDK clients and database connections.
How Lambda runs your code: the execution environment
When an event arrives, Lambda needs an execution environment: an isolated runtime with your code, its dependencies and the memory you configured. AWS documents three lifecycle phases.
Init
Lambda starts any extensions, bootstraps the runtime and runs your function's static code (everything outside the handler). For on-demand functions, the Init phase is limited to 10 seconds; if it does not finish, Lambda retries it at the first invocation with the configured function timeout. Functions using provisioned concurrency or SnapStart get a longer initialisation window.
Invoke
Lambda calls your handler with the event. The function timeout limits the whole Invoke phase, including any extensions. If the function crashes or times out, Lambda resets the environment and initialises it again for the next request.
Shutdown
When Lambda decides to retire an environment, it sends a Shutdown event to registered extensions so they can clean up. Between invocations, Lambda freezes the environment and may reuse it. AWS also notes that it terminates environments every few hours for maintenance, even for busy functions, so code must not assume an environment lives forever.
Cold starts and warm starts
A cold start is the time Lambda spends downloading your code and creating a new environment before running the handler. A warm start reuses an existing environment and skips that work. AWS states that cold starts typically occur in under 1% of invocations and range from under 100 ms to over a second. They are more common in development and test functions, which are invoked less often.
If you need predictable start times, provisioned concurrency keeps a set number of environments initialised in advance. SnapStart, available for some runtimes, runs Init when you publish a version and restores new environments from a snapshot. Trimming dependencies and loading rarely used libraries lazily also shortens Init.
How Lambda scales
Each execution environment handles one request at a time. When more requests arrive than there are free environments, Lambda creates more. The number of environments running at once is your function's concurrency.
The default regional quota is 1,000 concurrent executions per account, shared across functions, and it can be raised through Service Quotas. AWS also documents a per-function scaling rate of 1,000 new execution environments every 10 seconds. You can reserve concurrency for a critical function so others cannot starve it, or cap a function to protect a downstream database.
This matters when Lambda sits behind something that scales faster. AWS's own example: API Gateway's default throttle is 10,000 requests per second while Lambda's default concurrency is 1,000, so a traffic spike can produce throttling unless you plan for it. Load testing before launch shows which limit you hit first.
Invocation types
| Type | How it works | Typical sources | Payload limit |
|---|---|---|---|
| Synchronous | Caller waits for the response | API Gateway, function URLs, SDK Invoke calls | 6 MB request, 6 MB response |
| Asynchronous | Lambda queues the event and returns immediately; retries on error | S3 event notifications, SNS, EventBridge | 1 MB |
| Event source mapping | Lambda polls a stream or queue and invokes in batches | SQS, Kinesis, DynamoDB, Amazon MSK, Amazon MQ | Depends on source and batch size |
The type affects error handling. A synchronous caller sees the error directly. Asynchronous invocations are retried by Lambda, and you can send failures to a destination or dead-letter queue. With event source mappings, a failing batch is reprocessed by default until it succeeds or the records expire, and processing pauses for that shard, so set retry limits and failure destinations deliberately. AWS also warns that event source mappings process each event at least once, so make your handler idempotent.
How serverless architecture fits together
Lambda is rarely used alone. A serverless application is usually a set of managed services connected by events. A common web pattern looks like this:
- A user calls an HTTPS endpoint on Amazon API Gateway.
- API Gateway invokes a Lambda function synchronously.
- The function reads and writes data in DynamoDB.
- For slow work, the function puts a message on an SQS queue and returns quickly.
- A second function consumes the queue and does the heavy processing.
- Results or files land in S3, which can trigger further functions.
Each step scales independently, and each service is managed by AWS. The pieces communicate through events and queues, which decouples them: if the processing function slows down, messages wait in SQS instead of failing the user's request. Our post on building event-driven applications with Lambda and S3 walks through a full example.
Key limits to design around
| Resource | Limit (standard functions) |
|---|---|
| Timeout | 900 seconds (15 minutes) |
| Memory | 128 MB to 10,240 MB in 1 MB steps |
| /tmp storage | 512 MB to 10,240 MB |
| Environment variables | 4 KB total |
| Layers | 5 per function |
| .zip deployment package | 50 MB zipped (direct upload), 250 MB unzipped including layers |
| Container image | 10 GB uncompressed |
| Default concurrency | 1,000 per Region (can be increased) |
The 15-minute timeout is the limit people hit first. Long-running batch jobs, video processing or anything that waits on slow external systems either needs to be split into steps (often with AWS Step Functions) or moved to containers. Our article on Lambda timeout and payload limits goes into the workarounds.
Monitoring and observability
Lambda sends logs to Amazon CloudWatch Logs automatically, as long as the execution role allows it. Each invocation produces START, END and REPORT lines; the REPORT line shows duration, billed duration, memory size, maximum memory used and, on cold starts, the Init duration. CloudWatch metrics cover invocations, errors, throttles, duration and concurrent executions.
Useful alarms for most functions are errors above a threshold, throttles above zero, and duration approaching the timeout. For distributed tracing across API Gateway, Lambda and downstream calls, AWS X-Ray or OpenTelemetry-based tools show where time is spent.
Security basics
- Give each function its own execution role with only the permissions it needs. Avoid sharing one broad role across many functions.
- Store secrets in AWS Secrets Manager or Parameter Store rather than in plain environment variables, and cache them in the execution environment.
- Restrict who can invoke the function through its resource-based policy, especially for function URLs.
- Keep dependencies patched. Lambda manages the runtime, but your libraries are your responsibility.
- Attach the function to a VPC only when it needs private resources, and plan subnet sizes for the network interfaces it uses.
Runtime updates and deprecations
Serverless removes server patching, but it does not remove upgrades. AWS applies security updates to managed runtimes automatically by default. If you deploy a function as a container image, that job is yours: you rebuild from the latest base image and redeploy. In every case, your own code and dependencies remain your responsibility.
Runtimes also reach end of support. AWS sends notices at least 180 days before a runtime is deprecated, through email, the Health Dashboard and Trusted Advisor. After deprecation, the runtime stops receiving updates, and later AWS blocks creating and then updating functions that use it. Amazon Linux 2 reached end of life on 30 June 2026, and AWS recommends moving to Amazon Linux 2023 based runtimes. Track runtime identifiers in your infrastructure code so an upgrade is a one-line change plus a test run, and use function versions and aliases so you can roll back if the new runtime misbehaves.
When Lambda is the wrong choice
Lambda suits event-driven, short, stateless work with spiky or unpredictable traffic. It is a weaker fit for:
- Long-running processes that exceed 15 minutes.
- Workloads with steady, high traffic where always-on containers or instances cost less.
- Applications that need persistent local state, long-lived connections or specialised hardware.
- Latency-critical paths where any cold start is unacceptable and provisioned concurrency is not an option.
In those cases, Amazon ECS on Fargate, EKS or EC2 may be simpler. Many teams mix them: Lambda for glue and event handling, containers for the core services.
Deploying Lambda with infrastructure as code
Clicking functions together in the console works for experiments, but production functions belong in code. AWS SAM, AWS CDK, CloudFormation and Terraform can all define functions, triggers, roles and alarms in one place. Pair that with a CI/CD pipeline that runs tests, packages the function and deploys new versions behind an alias, and you can shift traffic gradually with CodeDeploy if you need safe rollouts. Our step-by-step guide to writing and deploying your first Lambda function shows the basics.
If you want guided practice with Lambda, VPCs, IAM and the rest of the core AWS services, the AWS Solutions Architect Associate training runs in our Kharadi, Pune classroom and live online for learners elsewhere.
Frequently asked questions
What is AWS Lambda in simple terms?
It is a service that runs your code when an event happens, without you managing servers. You provide the function and its configuration, and AWS handles provisioning, scaling and patching of the underlying infrastructure.
What is the maximum runtime of a Lambda function?
For standard functions, 900 seconds (15 minutes). Longer workflows should be split into steps, for example with Step Functions, or moved to containers.
How much memory can a Lambda function use?
Between 128 MB and 10,240 MB, in 1 MB increments. Lambda allocates CPU in proportion to memory, and a function has the equivalent of one vCPU at 1,769 MB.
What causes a Lambda cold start?
Lambda has to create a new execution environment, download your code and run initialisation code before the handler. AWS says cold starts typically affect under 1% of invocations.
How many Lambda functions can run at the same time?
The default regional quota is 1,000 concurrent executions per account, shared across functions. You can request an increase, and new accounts may start lower.
Is serverless always cheaper than servers?
No. Lambda is cost effective for spiky or low-volume workloads because you pay per use. For steady, high-volume traffic, always-on containers or instances can cost less. Compare using your own traffic pattern and the current AWS pricing page.
Which services commonly trigger Lambda?
API Gateway, S3 event notifications, SQS, SNS, EventBridge, DynamoDB Streams and Kinesis are among the most common triggers.
References
What's Your Reaction?
Like
1
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0