Soru

Zorluk: OrtaServerless Development with AWS Lambda

A developer is building a serverless application where an AWS Lambda function writes records to a legacy on-premises database. The database can handle a maximum of 10 concurrent connections. During peak hours, traffic spikes cause the Lambda function to scale, which overloads the database and causes connections to drop. How should the developer configure the Lambda function to prevent overloading the database?

  1. A
    Initialize the database client inside the handler method and set the Lambda execution timeout to 10 seconds.
  2. Set the reserved concurrency limit of the Lambda function to 10.Cevap
  3. C
    Place an Amazon SQS queue in front of the Lambda function and set the SQS visibility timeout to 10 seconds.
  4. D
    Deploy the Lambda function inside a private VPC subnet and configure the security group to limit the outbound concurrent connections to 10.

Cevap

Configure the Lambda function's reserved concurrency limit to 10 to restrict the maximum number of concurrent execution environments.
Setting the reserved concurrency limit of the Lambda function to 10 restricts the maximum number of concurrent instances of the function that can execute at any given time. This effectively limits the maximum number of concurrent database connections to 10, preventing the function from overloading the legacy database.

Adım Adım Çözüm

1
Analyze the database's connection limits and Lambda's automatic scaling behavior.
Identify that rapid horizontal scaling of Lambda functions during traffic spikes results in too many concurrent connection attempts, crashing the database.
By default, Lambda scales to meet demand, which can easily exceed the limits of downstream traditional or legacy systems.
2
Evaluate configuration methods to control the concurrent scaling of AWS Lambda.
Determine that reserved concurrency caps the maximum number of concurrent instances allowed to execute for a specific function.
Restricting the concurrent executions directly limits the maximum number of active database connections the function can establish.
3
Apply the configuration changes by setting the reserved concurrency limit to 10.
The Lambda function is constrained to a maximum of 10 concurrent executions, ensuring the legacy database connections never exceed 10.
This implements a hard limit on scale-out concurrency to match the downstream dependency constraints.

Anahtar Kavram

Managing AWS Lambda scaling and database connection pooling using Reserved Concurrency.

Alternatif Yöntem

Use Amazon RDS Proxy to manage and pool database connections, allowing the Lambda function to scale without overloading the database.
Tahmini Süre:1m 30s
Bu soruyu puanla