Soru

Zorluk: OrtaDebugging Lambda Execution and Configuration Issues

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?

  1. A
    The 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.
  2. 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
  3. C
    The IAM execution role assigned to the Lambda function lacks a trust policy that allows the Amazon RDS database service to assume the role.
  4. D
    The 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

1
Analyze the scope of the database connection client declaration in the function code.
The client is declared globally outside the handler function.
Variables declared outside the handler persist across warm starts due to execution environment reuse.
2
Identify the behavior difference between high-traffic load testing and low-traffic periods.
High-traffic requests succeed because the connection remains active, whereas low-traffic periods allow the database to terminate the idle connection.
Amazon RDS PostgreSQL has default idle connection timeout configurations that terminate inactive TCP connections.
3
Determine the failure mechanism during the subsequent execution.
The Lambda function attempts to execute query commands over the stale socket, leading to socket hang-ups or TCP timeout errors.
Since the connection client is not re-validated or re-initialized inside the handler, the dead connection is reused.

Anahtar Kavram

AWS Lambda execution environment reuse and global variable persistence (warm starts)
Bu soruyu puanla