An application uses an AWS Lambda function to process incoming messages. The function is configured to connect to an Amazon Aurora PostgreSQL database inside a private subnet of a VPC. The function also needs to call an external partner API on the public internet to validate user information. During load testing, the developer observes two issues: the Lambda function fails to connect to the external partner API, resulting in network connection timeouts, and the Aurora database frequently runs out of database connections during concurrent invocation spikes.
Which combination of actions should the developer take to resolve these issues? (Select two.)
- Deploy the Lambda function in the private subnet, configure a NAT Gateway in a public subnet, and route external traffic () from the private subnet to the NAT Gateway.Answer
- Initialize the database connection pool outside the Lambda handler function to reuse connection contexts across warm invocations.Answer
- CDeploy the Lambda function in a public subnet of the VPC and enable public IP address assignment in the Lambda function configuration.
- DInitialize the database connection pool inside the Lambda handler function and increase the function's execution timeout to ensure connections are cleaned up after each invocation.
- EConfigure the Amazon SQS visibility timeout of the source queue to be at least six times the Lambda function's timeout to allow the database to automatically close idle connections.
Answer
Deploy the Lambda function in the private subnet, route outbound internet traffic through a NAT Gateway, and initialize the database connection pool outside the handler function to allow reuse.
Deploying the Lambda function in private subnets with a NAT Gateway in a public subnet provides the necessary path to the public internet using static public IPs from the NAT Gateway. Additionally, initializing the database connection pool outside the handler ensures that the connection pool is persisted and reused across sequential warm invocations, preventing connection exhaustion.
Step-by-Step Solution
Key Concept
AWS Lambda VPC networking configuration and execution context reuse for database connection pooling.