A developer is troubleshooting an AWS Lambda function that processes customer orders. The Lambda function is configured to run inside a custom VPC in two private subnets to access an Amazon RDS database securely. During testing, the function times out when attempting to connect to an external payment processor's HTTP endpoint over the internet. Additionally, under load, the Lambda function frequently times out because it establishes a new database connection during each invocation, quickly exhausting database resources.
Which combination of actions will resolve these issues? (Select TWO.)
- Configuring a NAT gateway in a public subnet, and updating the route tables of the private subnets to route outbound internet traffic (0.0.0.0/0) through the NAT gateway.Answer
- Declaring the database connection client outside of the Lambda handler function to enable execution context reuse across warm starts.Answer
- CAttaching an Internet Gateway directly to the private subnets where the Lambda function is deployed, and assigning public IP addresses to the function configuration.
- DMoving the Lambda function to a public subnet in the VPC to allow direct route access to the Internet Gateway for external communication.
- ERe-initializing the database connection client inside the Lambda handler and executing a connection close method at the end of each invocation.
Answer
The correct options are configuring a NAT gateway in a public subnet and routing the private subnet's traffic through it, and declaring the database connection client outside of the handler function to reuse the execution context.
The correct options resolve both issues. Routing internet-bound traffic from private subnets through a NAT gateway in a public subnet allows the Lambda function to communicate with the external payment API. Declaring the database client outside the handler code ensures that the database connection is reused across invocations, mitigating connection overhead and latency.
Step-by-Step Solution
Key Concept
VPC networking configuration for outbound Lambda internet access and database connection optimization using execution context reuse.