Overview
AWS Lambda is a serverless, event-driven compute service that allows developers to run code without provisioning or managing servers. It automatically scales compute capacity to meet demand, executing code only when needed and scaling down to zero when idle. This operational model means users only pay for the actual compute time consumed, measured in milliseconds, and the number of requests processed according to AWS pricing documentation.
The service operates by executing functions, which are self-contained pieces of code, in response to various events. These events can originate from a wide array of AWS services, such as data uploads to Amazon S3 buckets, messages arriving in an Amazon SQS queue, changes in an Amazon DynamoDB table, or HTTP requests routed through Amazon API Gateway. Lambda supports multiple programming languages, including Python, Node.js, Java, Go, C#, Ruby, and PowerShell, and also allows custom runtimes. Developers can package their code as ZIP archives or container images as detailed in the AWS Lambda developer guide.
AWS Lambda is commonly employed for building event-driven microservices, automating backend processes, and processing data streams in real-time. For example, it can be used to resize images uploaded to cloud storage, filter and transform data logs, or power the backend for web and mobile applications. Its deep integration with the broader AWS ecosystem provides access to a comprehensive suite of services for databases, messaging, storage, and machine learning, simplifying the construction of complex, distributed applications. While offering significant operational benefits, constructing and managing complex serverless applications often requires understanding the interactions between Lambda functions and other AWS services as described in AWS architecture patterns.
Key features
- Event-driven execution: Functions are automatically triggered by events from over 200 AWS services, custom events, or direct API calls.
- Automatic scaling: Lambda automatically scales the number of concurrent function executions to match the incoming request rate without manual intervention.
- Integrated security: Leverages AWS Identity and Access Management (IAM) for granular permissions and integrates with AWS Key Management Service (KMS) for encryption.
- Container image support: Developers can package and deploy their functions as container images up to 10 GB in size, supporting custom runtimes and dependencies.
- Concurrency controls: Allows setting reserved concurrency limits for critical functions and provisioned concurrency to minimize cold starts for latency-sensitive applications.
- Monitoring and logging: Integrates with Amazon CloudWatch for monitoring function performance and logging outputs, and with AWS X-Ray for distributed tracing.
- Ephemeral execution environment: Each function invocation runs in an isolated, short-lived execution environment, ensuring clean state between calls.
- Layer support: Enables sharing common code, libraries, and custom runtimes across multiple functions without including them in every deployment package.
Pricing
AWS Lambda's pricing model is based on the number of requests and the compute duration consumed by your functions. There is a free tier available. Pricing details are current as of 2026-06-08.
| Metric | Details |
|---|---|
| Requests | First 1 million requests per month are free. Beyond free tier: $0.20 per 1 million requests. |
| Compute Duration | First 400,000 GB-seconds per month are free. Beyond free tier: calculated based on allocated memory and execution time. For example, $0.0000166667 per GB-second for x86 architecture. |
| Memory Allocation | Configurable from 128 MB to 10,240 MB. Higher memory allocations result in proportionally higher duration costs. |
| Data Transfer Out | Standard AWS data transfer rates apply after a free tier (typically 1 GB per month). |
For detailed and up-to-date pricing, refer to the official AWS Lambda pricing page.
Common integrations
- Amazon API Gateway: For building RESTful APIs and WebSocket APIs that trigger Lambda functions as backend logic as shown in the API Gateway developer guide.
- Amazon S3: To process data changes in S3 buckets, such as image resizing on upload or data processing for new files as described in the Lambda S3 integration guide.
- Amazon DynamoDB: To respond to data modifications in DynamoDB tables using DynamoDB Streams for real-time processing or replication as detailed in the Lambda DynamoDB integration.
- Amazon SQS: For processing messages in message queues, enabling asynchronous, decoupled architectures as outlined in the Lambda SQS documentation.
- Amazon Kinesis: To process real-time data streams for analytics, monitoring, and other applications as shown in the Lambda Kinesis integration guide.
- AWS Step Functions: For orchestrating complex workflows that involve multiple Lambda functions and other AWS services as described in the Step Functions developer guide.
Alternatives
- Google Cloud Functions: Google's serverless compute platform for event-driven applications, supporting multiple languages.
- Azure Functions: Microsoft Azure's serverless solution for executing code triggered by events, with extensive Visual Studio integration.
- Cloudflare Workers: A serverless platform that runs JavaScript, WebAssembly, or other languages at the edge of Cloudflare's global network.
- AWS Fargate: While not a direct function-as-a-service alternative, Fargate provides serverless compute for containers, offering more control over the runtime environment than Lambda.
Getting started
This example demonstrates a basic Python Lambda function that returns a "Hello from Lambda!" message. This can be deployed as a .zip file or a container image.
import json
def lambda_handler(event, context):
"""Sample pure Lambda function
Parameters
----------
event: dict,
Event data
context: object,
Lambda Context runtime methods and attributes
Returns
-------
dict
API Gateway compatible dict with status code 200 and a 'Hello from Lambda!' message.
"""
# Example of logging the incoming event
print(f"Received event: {json.dumps(event)}")
return {
"statusCode": 200,
"body": json.dumps({
"message": "Hello from Lambda!",
# "location": ip.city
}),
}
To deploy this function to AWS Lambda:
- Save the code above as
lambda_function.py. - Create a deployment package:
zip function.zip lambda_function.py. - In the AWS Management Console, navigate to Lambda and choose "Create function."
- Select "Author from scratch," provide a function name (e.g.,
MyHelloWorldFunction), and choose "Python 3.9" as the runtime. - Under "Code source," upload the
function.zipfile. - Configure an execution role with basic Lambda permissions.
- Test the function using the console's test feature.