Question

Difficulty: EasyDebugging Lambda Execution and Configuration Issues

An IoT telemetry ingestion application processes sensor data using an AWS Lambda function written in Node.js and writes the parsed payloads to an Amazon RDS database. During testing under heavy load, the Lambda function execution terminates prematurely after 33 seconds, and the database metrics show a spike in active client connections that reaches the database's limit. The database connection client initialization code is currently located inside the Lambda handler function.

Which TWO actions should be taken to resolve these configuration and execution issues?

  1. Increase the Lambda function's timeout configuration to a value that accommodates the database write latency.Answer
  2. Move the database connection initialization code outside of the Lambda handler function to reuse the database client across multiple invocations.Answer
  3. C
    Deploy the Lambda function in a public subnet of a VPC to allow direct internet access to the database.
  4. D
    Enable active tracing with AWS X-Ray to automatically close database connections at the end of each invocation.
  5. E
    Reduce the Lambda function's memory configuration to force faster garbage collection of unused database connections.

Answer

Increase the Lambda function's timeout configuration and move the database connection initialization code outside of the Lambda handler function.
Increasing the function timeout allows it to execute beyond the 3-second default threshold, which accommodates database write latency. Moving the database client initialization outside of the handler leverages the Lambda execution context reuse, allowing subsequent requests to share the connection pool and avoiding database connection exhaustion.

Step-by-Step Solution

1
Analyze the log metrics to identify that the execution terminates early because of the default 3-second timeout limit.
Confirming that the timeout limit needs to be increased.
The function requires more time to complete database connections and writes.
2
Analyze the database connection limit error to identify that new connections are created for every single invocation.
Confirming that the database client is initialized inside the handler.
Initializing the client inside the handler forces a new connection on every invocation, causing connection pool exhaustion.
3
Modify the code to move the initialization of the database client outside the handler and update the Lambda timeout configuration in the AWS console or IaC template.
Connection reuse is enabled across warm starts, and execution times are allowed to exceed 3 seconds.
This resolves both the timeout and connection exhaustion issues by optimizing execution context reuse and configuration parameters.

Key Concept

AWS Lambda configuration tuning and execution context optimization
Rate this question