AWS Lambda
AWS serverless compute service that runs code in response to events without provisioning or managing servers, automatically scaling from zero to thousands of concurrent executions.
What it is
AWS Lambda is Amazon's Functions as a Service (FaaS) offering. It lets you run code without provisioning servers — you upload your function, define what events trigger it, and AWS handles the rest: provisioning, scaling, high availability, and monitoring.
Execution model
- An event triggers the function (HTTP request, SQS message, S3 file, etc.)
- Lambda provisions an execution environment (or reuses an existing one)
- Your code executes
- Lambda charges by duration (ms) and allocated memory
- The environment may stay "warm" for subsequent requests
Key features
- Runtimes: Node.js, Python, Java, Go, .NET, Ruby, or custom (container)
- Memory: 128 MB to 10 GB (CPU scales proportionally)
- Maximum duration: 15 minutes per invocation
- Concurrency: up to 1,000 by default (expandable)
- Layers: shared libraries across functions
- Provisioned concurrency: eliminates cold starts for critical functions
Common triggers
| Trigger | Use case |
|---|---|
| API Gateway | REST/HTTP APIs |
| S3 | File processing |
| DynamoDB Streams | Reacting to data changes |
| SQS | Queue processing |
| EventBridge | Scheduled or service events |
| Cognito | Authentication hooks |
Cold starts
A "cold start" occurs when Lambda must initialize a new environment:
- Typically 100ms-1s for interpreted runtimes
- Can be several seconds for Java/.NET
- Mitigation: provisioned concurrency, keep functions small, SnapStart (Java)
Best practices
- Keep functions small and focused
- Reuse connections (DB, HTTP) outside the handler
- Use environment variables for configuration
- Implement idempotency for retries
- Monitor with CloudWatch and X-Ray
Why it matters
Lambda changed the way we think about infrastructure: instead of provisioning servers, you define functions that execute in response to events. For workloads with variable traffic, the pay-per-execution model can reduce costs by orders of magnitude compared to always-on servers.
References
- AWS Lambda Documentation — Official documentation.
- Lambda Power Tuning — Tool for optimizing memory/cost.
- Lambda Best Practices — AWS, 2024. Official best practices for Lambda functions.