Soru

Zorluk: KolayMessage-Based Integration using Amazon SQS and SNS

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

  1. Configure the SQS queue's visibility timeout to be at least six times the Lambda function's timeout.Cevap
  2. Initialize the database connection client outside of the Lambda handler function.Cevap
  3. C
    Decrease the SQS queue's visibility timeout to 55 seconds to allow failed messages to be retried faster.
  4. D
    Hardcode the database access credentials directly in the SDK client initialization within the Lambda function.
  5. E
    Rely 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

1
Analyze the duplicate processing issue.
The messages take 1515 seconds to process. SQS requires the visibility timeout to be greater than the processing time (and ideally at least six times the Lambda function's timeout) to prevent duplicate processing by other concurrent consumers.
If the visibility timeout is too short, SQS assumes the consumer failed and makes the message visible again.
2
Analyze the database connection exhaustion issue.
Initialize connection clients outside the Lambda handler function to reuse connections across container executions.
Creating a new connection client inside the handler function on every invocation will quickly exhaust the database's available connections.

Anahtar Kavram

Managing SQS visibility timeout and Lambda execution context connection reuse
Tahmini Süre:1m 0s
Bu soruyu puanla