Lambda Function Configuration and Performance
RAM Configuration
- Default RAM: 128 MB
- Maximum RAM: 10 GB
- Increments: 1 MB
- More RAM = More vCPU credits
- At 1,792 MB RAM, you get 1 full vCPU
- Beyond 1,792 MB, multi-threading is needed to utilize additional vCPUs
- Increase RAM for CPU-bound (computation-heavy) applications to improve performance
Timeout Settings
- Default timeout: 3 seconds
- Maximum timeout: 900 seconds (15 minutes)
- Use cases longer than 15 minutes should consider Fargate, ECS, or EC2
Execution Context
- Maintains temporary runtime environment
- Reuses database connections, HTTP clients, SDK clients
- Includes
/tmp directory for file storage across executions
Code Optimization
- Bad Example: Initializing database connection inside the handler function
- Best Practice: Initialize expensive operations outside the handler for reuse