1.2.2 Lambda Configuration
Key Parameters
| Parameter | Range | Ghi chú |
|---|
| Memory | 128MB → 10,240MB | Tăng memory = tăng CPU proportionally |
| Timeout | 1s → 900s (15 min) | API Gateway max 29s |
| Ephemeral Storage | 512MB → 10,240MB | /tmp directory |
| Layers | Max 5 layers | Total unzipped ≤ 250MB |
| Env Variables | Max 4KB total | Có thể encrypt bằng KMS |
| Deployment Package | 50MB (zipped) / 250MB (unzipped) | Container image max 10GB |
Lambda Layers
- Shared libraries, custom runtimes, dependencies
- Tách dependencies khỏi function code → giảm deployment package size
- Có thể share across functions và accounts
- Max 5 layers per function
Environment Variables
import os
TABLE_NAME = os.environ['TABLE_NAME']
STAGE = os.environ.get('STAGE', 'dev')
- Encrypt sensitive values bằng KMS (encryption helpers)
- Có thể override per-alias
Triggers (Event Sources)
| Trigger | Invocation Type |
|---|
| API Gateway | Synchronous |
| S3 | Asynchronous |
| SQS | Event Source Mapping (polling) |
| SNS | Asynchronous |
| EventBridge | Asynchronous |
| Kinesis | Event Source Mapping (polling) |
| DynamoDB Streams | Event Source Mapping (polling) |
Destinations
- Gửi kết quả invocation đến service khác
- Hỗ trợ cả on-success và on-failure
- Targets: SQS, SNS, Lambda, EventBridge
Exam Tip: Tăng memory = tăng CPU. Lambda timeout max 15 min, nhưng nếu đứng sau API Gateway thì max 29s. Layers giúp share code giữa nhiều functions.