★ Featured by FindUtils

AWS Lambda & Serverless Patterns

AWS Lambda with API Gateway, DynamoDB, SQS, and serverless architecture patterns for production workloads.

Claude CodeCursorGitHub CopilotWindsurfClineCodex / OpenAIGemini CLI
Updated 2026-04-05
CLAUDE.md
# AWS Lambda & Serverless Patterns

You are an expert in AWS Lambda, serverless architecture, and AWS cloud services.

Architecture:
- Use single-purpose functions: one Lambda per API endpoint or event handler
- Keep cold start times low: minimize package size, use provisioned concurrency for critical paths
- Use Lambda layers for shared dependencies across functions
- Use environment variables for configuration; AWS Systems Manager Parameter Store for secrets
- Structure code: handler (thin) -> service (business logic) -> repository (data access)

API Gateway:
- Use HTTP API (v2) for simple REST APIs (cheaper, faster than REST API v1)
- Use REST API (v1) when you need request validation, WAF, or usage plans
- Enable CORS at the API Gateway level, not in Lambda code
- Use Lambda authorizers for custom auth; Cognito for managed auth
- Set appropriate throttling and burst limits per route

Data Patterns:
- DynamoDB for key-value and document storage (single-digit ms latency)
- Design DynamoDB tables for access patterns: single-table design preferred
- Use SQS for async processing: decouple producers from consumers
- Use EventBridge for event-driven architectures across services
- Use S3 for file storage with pre-signed URLs for direct upload/download

Performance:
- Minimize cold starts: keep deployment package under 50MB, use arm64 (Graviton2)
- Use connection pooling: reuse HTTP clients and DB connections across invocations
- Move initialization outside the handler function (runs once per cold start)
- Use Lambda Power Tuning to find optimal memory/cost configuration
- Enable X-Ray tracing for distributed debugging

Error Handling:
- Use Dead Letter Queues (DLQ) for failed async invocations
- Implement retry with exponential backoff for downstream service calls
- Use structured logging with correlation IDs across services
- Set appropriate timeout: shorter than API Gateway timeout (29s max)
- Use Lambda Destinations for async invocation success/failure routing

Add to your project root CLAUDE.md file, or append to an existing one.

Tags

awslambdaserverlessdynamodbapi-gatewaycloud