A developer is troubleshooting an AWS Lambda function that processes customer orders and writes them to an Amazon RDS PostgreSQL database located in a private subnet. The Lambda function is configured to run inside the same VPC and private subnets. Additionally, the Lambda function must call a third-party payment gateway endpoint on the public internet. During execution, the Lambda function successfully connects to the database but fails with a timeout error when attempting to reach the payment gateway. Which configuration change is required to resolve this execution issue?
- Deploy a NAT Gateway in a public subnet of the VPC, and add a route in the private subnet's route table directing destination traffic of to the NAT Gateway.Answer
- BAssociate the Lambda function with the public subnets of the VPC to allow direct outbound communication via the VPC's Internet Gateway.
- CIncrease the execution timeout limit of the Lambda function to minutes to accommodate the external payment gateway response times.
- DAttach an Internet Gateway directly to the Lambda function's elastic network interface (ENI) and assign a public IP address using the Lambda configuration console.
Answer
Deploy a NAT Gateway in a public subnet of the VPC, and add a route in the private subnet's route table directing destination traffic of to the NAT Gateway.
The correct answer is correct because AWS Lambda functions configured within a VPC do not receive public IP addresses on their elastic network interfaces (ENIs). Consequently, they cannot communicate directly with the internet through an Internet Gateway. To access public endpoints while remaining inside a VPC, the Lambda function must run in private subnets, and the outbound traffic must be routed through a NAT Gateway positioned in a public subnet.
Step-by-Step Solution
Key Concept
VPC Networking for AWS Lambda Functions