Soru

Zorluk: OrtaServerless Development with AWS Lambda

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.)

  1. Create an Amazon RDS Proxy for the database and configure the Lambda function to connect to the RDS Proxy endpoint.Cevap
  2. Initialize the database connection pool outside the Lambda handler function to enable connection reuse across warm invocations.Cevap
  3. C
    Initialize and close the database connection inside the Lambda handler function on every invocation to ensure connections are immediately released.
  4. D
    Increase the Lambda function's execution timeout limit to allow the database client more time to establish and close connections.
  5. E
    Configure the Lambda function to run in a public VPC subnet and associate it with a public IP address to bypass internal database routing delays.

Cevap

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.

Adım Adım Çözüm

1
Analyze the cause of database connection exhaustion under serverless scaling.
Identify that AWS Lambda functions scale horizontally by creating separate execution environments, which leads to many concurrent database connections if each environment initializes a connection.
Understanding why the problem occurs is necessary to apply connection pooling.
2
Introduce a connection proxying mechanism.
Deploy an Amazon RDS Proxy between the Lambda function and the RDS PostgreSQL instance to manage database connection reuse.
RDS Proxy buffers incoming traffic and limits the actual concurrent connections established on the database.
3
Optimize the Lambda function initialization code.
Move the database connection helper and initialization logic outside the handler method block.
Moving client instantiation outside the handler enables subsequent executions in the same container instance (warm starts) to reuse the active connection pool, reducing connection latency.

Anahtar Kavram

AWS Lambda execution context reuse and database connection pooling using Amazon RDS Proxy.
Bu soruyu puanla