A developer has deployed a Node.js-based AWS Lambda function that retrieves user profiles from an Amazon RDS PostgreSQL database. To minimize latency, the database connection client is declared and initialized globally outside the handler function. During load testing with high request volumes, the function performs correctly. However, during periods of low traffic, subsequent requests fail with database connection errors, causing the Lambda function to time out. Which of the following is the most likely cause of this issue?
- AThe Lambda function is configured to run in a private subnet, preventing it from reaching the database endpoint in another subnet without routing through a NAT Gateway.
- The function is attempting to reuse a database connection that was established during a previous container execution and has since been closed by the database due to idle timeout.Cevap
- CThe IAM execution role assigned to the Lambda function lacks a trust policy that allows the Amazon RDS database service to assume the role.
- DThe function retrieves database credentials from Systems Manager Parameter Store, which does not support caching parameters during container reuse, leading to authentication failures.
Cevap
The Lambda function is attempting to reuse a database connection that was initialized outside the handler function but has since been terminated by the database due to inactivity.
The correct option identifies that the global database client is reused during warm starts. Because of the low-traffic period, the database terminates the idle connection, leaving a stale connection object in the Lambda execution environment. Subsequent handler invocations attempt to reuse this dead connection, causing timeouts.
Adım Adım Çözüm
Anahtar Kavram
AWS Lambda execution environment reuse and global variable persistence (warm starts)