1.2.1 Lambda trong VPC

Lambda trong VPC

Khi nào cần đặt Lambda trong VPC?

  • Truy cập private resources: RDS, ElastiCache, OpenSearch
  • Lambda mặc định chạy ngoài VPC (AWS-managed network)

Cấu hình

  • VPC ID, Subnet IDs (ít nhất 2 AZs), Security Group IDs
  • Lambda tạo ENI (Elastic Network Interface) trong subnet
  • Execution role cần: AWSLambdaVPCAccessExecutionRole

Internet Access

  • Lambda trong VPC KHÔNG có internet access mặc định
  • Cần NAT Gateway trong public subnet (tốn phí)
  • Hoặc VPC Endpoints cho AWS services

VPC Endpoints

TypeServicesChi phí
GatewayS3, DynamoDBMiễn phí
InterfaceHầu hết AWS services khácTính phí per hour + data

Quan trọng: Nếu Lambda trong VPC cần gọi AWS services (SQS, SNS, KMS…) mà không có NAT Gateway → dùng Interface VPC Endpoint. S3 và DynamoDB dùng Gateway Endpoint (miễn phí).