1.2.2 Lambda Configuration

Configure Lambda Functions

Key Parameters

ParameterRangeGhi chú
Memory128MB → 10,240MBTăng memory = tăng CPU proportionally
Timeout1s → 900s (15 min)API Gateway max 29s
Ephemeral Storage512MB → 10,240MB/tmp directory
LayersMax 5 layersTotal unzipped ≤ 250MB
Env VariablesMax 4KB totalCó thể encrypt bằng KMS
Deployment Package50MB (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)

TriggerInvocation Type
API GatewaySynchronous
S3Asynchronous
SQSEvent Source Mapping (polling)
SNSAsynchronous
EventBridgeAsynchronous
KinesisEvent Source Mapping (polling)
DynamoDB StreamsEvent Source Mapping (polling)

Destinations

  • Gửi kết quả invocation đến service khác
  • Hỗ trợ cả on-successon-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.