A developer is implementing an AWS Lambda function that processes customer feedback and calls a third-party translation API over the internet. The Lambda function is configured to run inside a custom VPC and is associated with two public subnets. The VPC has an Internet Gateway, and the route table for the public subnets contains a route pointing 0.0.0.0/0 to the Internet Gateway. During testing, the Lambda function fails to connect to the translation API and terminates after reaching its maximum timeout limit. What configuration change should the developer make to resolve this connection issue?
- AEnable the auto-assign public IP setting in the VPC subnets associated with the Lambda function to allow the function's network interfaces to receive public IP addresses.
- Configure the Lambda function to run in private subnets, and route internet-bound traffic through a NAT Gateway.Answer
- CIncrease the execution timeout limit of the Lambda function and set the reserved concurrency to 1 to prevent connection pool exhaustion.
- DAttach an Internet Gateway directly to the Lambda function's network interface and update the security group rules to allow outbound HTTP/HTTPS traffic.
Answer
Configure the Lambda function to run in private subnets, and route internet-bound traffic through a NAT Gateway.
The correct answer is to configure the Lambda function to run in private subnets and route internet-bound traffic through a NAT Gateway. This is because AWS Lambda functions configured within a VPC do not receive public IP addresses, even when associated with public subnets. As a result, they cannot route traffic directly to an Internet Gateway. Placing the Lambda function in private subnets and routing internet-bound traffic through a NAT Gateway (which has a public IP address) enables the function to reach external web APIs.
Step-by-Step Solution
Key Concept
AWS Lambda VPC networking and outbound internet access constraints