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?
- AInitialize the database client inside the handler method and set the Lambda execution timeout to 10 seconds.
- Set the reserved concurrency limit of the Lambda function to 10.Answer
- CPlace an Amazon SQS queue in front of the Lambda function and set the SQS visibility timeout to 10 seconds.
- DDeploy the Lambda function inside a private VPC subnet and configure the security group to limit the outbound concurrent connections to 10.
Answer
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.
Step-by-Step Solution
Key Concept
Managing AWS Lambda scaling and database connection pooling using Reserved Concurrency.
Alternative Method
Use Amazon RDS Proxy to manage and pool database connections, allowing the Lambda function to scale without overloading the database.
Estimated Time:1m 30s