Lambda and Serverless
AWS Lambda lets you run code without provisioning or managing servers. Upload your code, configure triggers, and Lambda handles everything from scaling to patching. You pay only for the compute time you consume.
How Lambda Works
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β LAMBDA WORKFLOW β
β β
β Trigger Lambda Function Response β
β βββββββ ββββββββββββββββ βββββββ β
β β API ββββββββββΆβ Your Code ββββββΆβ JSONβ β
β βGatewayβ β (Node.js, β β β β
β βββββββ β Python, β βββββββ β
β β Java, etc) β β
β βββββββ ββββββββ¬ββββββββ β
β β S3 ββββββββββΆ β β
β βEventβ β AWS handles: β
β βββββββ β - Server provisioning β
β β - Scaling (0 to 1000s) β
β βββββββ β - Patching β
β βCloudββββββββββΆ β - Monitoring β
β βWatchβ β - Logging β
β βββββββ ββββββββββββββββββββββββββββ
β β
β Pay only when code runs: $0.20 per 1M requests β
β + compute time ($0.0000166667 per GB-second) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Lambda Limits and Features
Memory: 128 MB to 10 GB of memory (proportional CPU).
Timeout: Up to 15 minutes per invocation.
Package size: 50 MB (zipped), 250 MB (unzipped) for direct upload.
Concurrent executions: 1,000 by default (can be increased via support).
Layers: Share common code and dependencies across functions.
Common Lambda Patterns
ββββββββββββββββββββββββββββββββββββββββββββββββ
β Pattern β Example β
ββββββββββββββββββββββββΌββββββββββββββββββββββββ€
β API Backend β API Gateway β Lambda β
β β β DynamoDB β
β File Processing β S3 upload β Lambda β
β β β resize/convert β
β Scheduled Tasks β EventBridge β Lambda β
β β (cron-like jobs) β
β Data Streaming β Kinesis β Lambda β
β β β process records β
β Chatbot β Lex β Lambda β
β β β business logic β
ββββββββββββββββββββββββ΄ββββββββββββββββββββββββ
Lambda Best Practices
Keep functions small and focused. Use environment variables for configuration. Implement error handling with dead-letter queues. Use Lambda Layers for shared dependencies. Monitor with CloudWatch Logs and X-Ray tracing. Test locally with SAM CLI before deploying.