A developer is developing a serverless application that uses an AWS Lambda function to write logs and user status updates to an Amazon RDS PostgreSQL database instance. During high-concurrency load testing, the database starts throwing connection limit exhaustion errors. Additionally, the developer notices that each invocation suffers from high latency because a new database connection is created every time. Which TWO actions should the developer take to resolve the database connection limit errors and improve connection latency? (Select TWO.)
- Create an Amazon RDS Proxy for the database and configure the Lambda function to connect to the RDS Proxy endpoint.Answer
- Initialize the database connection pool outside the Lambda handler function to enable connection reuse across warm invocations.Answer
- CInitialize and close the database connection inside the Lambda handler function on every invocation to ensure connections are immediately released.
- DIncrease the Lambda function's execution timeout limit to allow the database client more time to establish and close connections.
- EConfigure the Lambda function to run in a public VPC subnet and associate it with a public IP address to bypass internal database routing delays.
Answer
Amazon RDS Proxy should be created to pool and share database connections, and the database connection pool should be initialized outside the Lambda handler function to enable execution context reuse.
Using Amazon RDS Proxy allows connection pooling and sharing, which prevents database connection exhaustion during high-concurrency traffic spikes. Additionally, initializing the database connection pool outside of the Lambda handler function enables the SDK clients and database connections to be reused across subsequent invocations that run in the same warm execution context, reducing overall connection setup latency.
Step-by-Step Solution
Key Concept
AWS Lambda execution context reuse and database connection pooling using Amazon RDS Proxy.