An AWS Lambda function is configured to run inside private subnets of a custom VPC to retrieve records from an Amazon RDS PostgreSQL database. After retrieving the records, the function attempts to upload a compiled report to an Amazon S3 bucket. The function successfully connects to the database but consistently times out when attempting to write to the S3 bucket. The VPC has no NAT Gateway or internet connectivity. Which action should the developer take to resolve this execution issue?
- AMove the Lambda function to a public subnet within the VPC and enable the auto-assign public IP configuration.
- BIncrease the Lambda function's execution timeout limit to 15 minutes to allow the connection retry attempts to succeed.
- Create a Gateway VPC Endpoint for Amazon S3 and associate it with the route table of the Lambda function's subnets.Answer
- DModify the Lambda function's IAM execution role to include the s3:PutObject permission for the target S3 bucket.
Answer
Create a Gateway VPC Endpoint for Amazon S3 and associate it with the route table of the Lambda function's subnets.
The correct answer is to create a Gateway VPC Endpoint for Amazon S3. When a Lambda function runs inside a custom VPC without internet egress (no NAT Gateway), it can communicate locally but cannot reach public AWS endpoints. A Gateway VPC Endpoint establishes private connectivity to Amazon S3 directly from the private subnet's route table.
Step-by-Step Solution
Key Concept
Debugging network routing for Lambda functions configured inside a custom VPC