AWS Lambda — Serverless Functions
AWS Lambda — Serverless Functions
Section titled “AWS Lambda — Serverless Functions”AWS Lambda is a serverless compute service that lets you run code in response to events without provisioning or managing servers. You pay only for the compute time consumed — there is no charge when code is not running.
In Azure terms: AWS Lambda = Azure Functions
How Lambda Works
Section titled “How Lambda Works”- You upload your function code (or write inline)
- You configure a trigger (event source)
- When the trigger fires, Lambda automatically:
- Allocates compute resources
- Runs your function
- Scales automatically (from 1 to 1,000+ concurrent executions)
- Reports metrics to CloudWatch
Supported Runtimes
Section titled “Supported Runtimes”| Runtime | Versions |
|---|---|
| Node.js | 22.x, 24.x |
| Python | 3.11, 3.12, 3.13, 3.14 |
| Java | 8, 11, 17, 21, 25 |
| .NET | .NET 10 (dotnet10) |
| Ruby | 3.3, 3.4 |
| Go | provided.al2023 (custom runtime) |
| Custom Runtime | Bring your own via Lambda Layers or container images |
AWS has announced Node.js 26 and Python 3.15 runtimes for late 2026. Older runtimes are deprecated on a published schedule, so check the Lambda runtimes page before you choose one.
Lambda Triggers (Event Sources)
Section titled “Lambda Triggers (Event Sources)”| Trigger Type | Examples |
|---|---|
| API | API Gateway, Function URL (direct HTTPS) |
| Storage | S3 object created/deleted, DynamoDB Streams |
| Messaging | SQS, SNS, Kinesis, EventBridge |
| Scheduling | EventBridge Scheduler (cron-like) |
| Auth | Cognito User Pools (custom auth flows) |
| Other | CloudFront (Lambda@Edge), ALB, IoT |
Lambda Configuration
Section titled “Lambda Configuration”| Setting | Description |
|---|---|
| Memory | 128 MB to 10,240 MB (CPU scales proportionally) |
| Timeout | 1 second to 15 minutes (900 seconds) |
| Concurrency | Up to 1,000 concurrent executions per region (soft limit) |
| Execution Role | IAM Role that grants the function permissions |
| Environment Variables | Key-value config passed to function at runtime |
| Layers | Shared dependencies/libraries across functions |
| VPC | Optional — attach to a VPC to access private resources |
Lambda Pricing
Section titled “Lambda Pricing”| Metric | Price |
|---|---|
| Requests | $0.20 per 1 million requests |
| Duration | $0.0000166667 per GB-second |
| Free tier | 1 million requests/month + 400,000 GB-seconds/month forever |
Lambda’s free tier never expires — it’s not limited to the first 12 months.
Lambda Function Anatomy (Python)
Section titled “Lambda Function Anatomy (Python)”import json
def lambda_handler(event, context): # event: the trigger payload (dict) # context: runtime info (function name, remaining time, etc.)
name = event.get('name', 'World')
return { 'statusCode': 200, 'body': json.dumps(f'Hello, {name}!') }Lambda with API Gateway
Section titled “Lambda with API Gateway”A common pattern: API Gateway as the trigger makes Lambda an HTTP endpoint:
Client → API Gateway → Lambda → Response# Create a Lambda functionaws lambda create-function \ --function-name my-function \ --runtime python3.12 \ --role arn:aws:iam::123456789012:role/lambda-role \ --handler lambda_function.lambda_handler \ --zip-file fileb://function.zip
# Invoke a Lambda functionaws lambda invoke \ --function-name my-function \ --payload '{"name": "AWS"}' \ response.json
# Update function codeaws lambda update-function-code \ --function-name my-function \ --zip-file fileb://function.zipCold Start vs Warm Start
Section titled “Cold Start vs Warm Start”| Scenario | Latency | Description |
|---|---|---|
| Cold start | 100ms – 1s+ | Lambda spins up a new execution environment |
| Warm start | < 10ms overhead | Reuses an existing execution environment |
Tips to reduce cold starts:
- Use Provisioned Concurrency (keeps environments warm, extra cost)
- Keep deployment packages small
- Use lighter runtimes (Python, Node.js) for latency-sensitive functions
- Use Lambda SnapStart (Java only)
Lambda vs Azure Functions
Section titled “Lambda vs Azure Functions”| Feature | AWS Lambda | Azure Functions |
|---|---|---|
| Max timeout | 15 minutes | 10 minutes (Consumption), unlimited (Dedicated/Flex) |
| Max memory | 10 GB | 1.5 GB (Consumption) |
| Triggers | API GW, S3, SQS, SNS, EventBridge, DynamoDB | HTTP, Blob, Queue, Service Bus, Event Hub, Timer |
| Hosting plans | No choice — always serverless | Consumption, Premium, Dedicated |
| Warm instances | Provisioned Concurrency | Premium (pre-warmed) |
| Languages | Node, Python, Java, .NET, Ruby, Go | C#, JS, Python, Java, PowerShell, Go |
Best Practices
Section titled “Best Practices”- Keep functions small and single-purpose
- Store secrets in AWS Secrets Manager or SSM Parameter Store, not environment variables
- Set appropriate timeouts — don’t leave at default 3 seconds for I/O-bound functions
- Enable X-Ray tracing for distributed debugging
- Use Dead Letter Queues (DLQ) for failed async invocations
- Tag functions with environment and team for cost tracking