A serverless order processing application utilizes an AWS Lambda function to send confirmation emails via a third-party API. The function is also configured to access an Amazon Aurora PostgreSQL database in a private subnet. The developer has configured the Lambda function to run inside the private subnets of the VPC to enable database access.
During testing, the developer observes two issues:
1. The Lambda function fails to connect to the third-party email API.
2. The database connection pool is frequently exhausted, and Lambda execution logs show connection timeouts during concurrent invocations.
Which two actions should the developer take to resolve these issues?
- Initialize the database connection client outside the Lambda handler function to enable connection reuse across invocations.Answer
- Provision a NAT Gateway in a public subnet, and configure the route table of the Lambda private subnets to route outbound internet traffic through the NAT Gateway.Answer
- CMove the Lambda function configuration to public subnets within the VPC to enable direct internet access.
- DImplement logic within the handler function to terminate the database connection pool at the end of each execution, and extend the Lambda function's timeout configuration.
- ECreate a VPC gateway endpoint for the third-party email API and associate it with the route tables of the Lambda subnets.
Answer
To resolve the issues, the developer must initialize the database connection client outside the Lambda handler function to enable connection reuse, and provision a NAT Gateway in a public subnet to route outbound internet traffic from the private subnets.
The correct solution involves reusing database connections by instantiating the client outside the handler, and establishing internet connectivity for the private subnet using a NAT Gateway.
Step-by-Step Solution
Key Concept
Troubleshooting VPC egress routing for Lambda functions and optimizing resource utilization through execution context reuse.