A developer is building an integration where an application publishes messages to an Amazon SNS topic. An Amazon SQS queue is subscribed to the topic, and an AWS Lambda function processes messages from the queue. The messages take approximately seconds to process. During testing, the developer observes that messages are frequently being processed multiple times, and the Lambda function is running out of database connections. Which of the following actions should the developer take to resolve these issues? (Select TWO.)
- Configure the SQS queue's visibility timeout to be at least six times the Lambda function's timeout.Cevap
- Initialize the database connection client outside of the Lambda handler function.Cevap
- CDecrease the SQS queue's visibility timeout to seconds to allow failed messages to be retried faster.
- DHardcode the database access credentials directly in the SDK client initialization within the Lambda function.
- ERely on the Lambda execution context to automatically close database connection pools at the end of each invocation.
Cevap
Configure the SQS visibility timeout to be at least six times the Lambda function's timeout, and initialize the database connection client outside of the Lambda handler function.
Configuring the SQS visibility timeout to be at least six times the Lambda function timeout ensures that messages do not become visible to other consumers before the current Lambda function invocation has finished processing them or retrying. Initializing the database connection client outside of the Lambda handler function allows subsequent invocations that reuse the same execution context to reuse the existing database connection, preventing connection exhaustion.
Adım Adım Çözüm
Anahtar Kavram
Managing SQS visibility timeout and Lambda execution context connection reuse
Tahmini Süre:1m 0s