A developer is troubleshooting an AWS Lambda function that processes customer orders. The function is configured to connect to an Amazon RDS PostgreSQL database in a private subnet of a custom VPC. The function also needs to call a third-party payment provider's public API endpoint over the internet. The developer configured the Lambda function to run in the public subnets of the VPC and associated it with a security group that allows all outbound traffic. During execution, the function successfully queries the database but times out when attempting to reach the payment provider's API.
Which of the following actions will resolve this connectivity issue?
- Associate the Lambda function with the private subnets of the VPC, deploy a NAT Gateway in a public subnet, and route internet-bound traffic from the private subnets through the NAT Gateway.Answer
- BEnable the 'Assign Public IP' setting in the Lambda function's VPC configuration to allow the function to route traffic directly through the VPC's Internet Gateway.
- CAdd a route to the public subnet's route table with destination 0.0.0.0/0 targeting the Internet Gateway, and attach an Elastic IP address to the Lambda function's elastic network interfaces (ENIs).
- DIncrease the Lambda function's execution timeout to 15 minutes and allocate more memory to allow the connection pool to establish a secure connection over the VPC internet route.
Answer
Associate the Lambda function with the private subnets of the VPC, deploy a NAT Gateway in a public subnet, and route internet-bound traffic from the private subnets through the NAT Gateway.
The correct solution is to associate the Lambda function with the private subnets of the VPC, deploy a NAT Gateway in a public subnet, and route internet-bound traffic from the private subnets through the NAT Gateway. AWS Lambda functions associated with a VPC do not receive public IP addresses. Even if placed in a public subnet, they cannot route traffic directly to the Internet Gateway. Moving the function to private subnets and routing outbound traffic through a NAT Gateway resolves this limitation.
Step-by-Step Solution
Key Concept
AWS Lambda VPC networking and outbound internet access