Soru

Zorluk: OrtaMessage-Based Integration using Amazon SQS and SNS

An application uses an Amazon SNS topic to publish customer signup events. These events are fanned out to an Amazon SQS queue, which is processed by a downstream AWS Lambda function. During peak traffic, the developers notice that the Lambda function is frequently invoked with duplicate messages for the same customer signup, although the message was published to the SNS topic only once.

Which of the following configuration changes is the most effective solution to prevent these duplicate invocations?

  1. Increase the visibility timeout of the Amazon SQS queue to be at least six times the timeout of the AWS Lambda function.Cevap
  2. B
    Decrease the visibility timeout of the Amazon SQS queue to 0 seconds so that messages are instantly hidden from other consumers as soon as Lambda retrieves them.
  3. C
    Modify the SQS client initialization inside the Lambda function code to hardcode static IAM user credentials to speed up execution time and bypass role assumption delays.
  4. D
    Store the processed message IDs in a global array in the Lambda execution context to deduplicate incoming messages, assuming the context persists across all invocations.

Cevap

Increase the visibility timeout of the Amazon SQS queue to be at least six times the timeout of the AWS Lambda function.
Increasing the visibility timeout of the Amazon SQS queue to at least six times the timeout of the AWS Lambda function prevents SQS from making the message visible again while the current Lambda execution is still processing it. This ensures that Lambda has sufficient time to complete execution and delete the message from the queue before it can be delivered to another worker.

Adım Adım Çözüm

1
Analyze the cause of duplicate invocations in an SQS-triggered Lambda function.
Identify that the visibility timeout must accommodate the processing time of the consumer function plus retries.
If the visibility timeout is shorter than the Lambda execution time, SQS makes the message visible again, leading to duplicate reads.
2
Determine the AWS recommended relationship between SQS visibility timeout and Lambda timeout.
The visibility timeout of the source queue must be set to at least six times the timeout of the Lambda function.
This ratio accommodates multiple retries and avoids duplicate processing if a function is throttled while handling a batch.

Anahtar Kavram

SQS visibility timeout configuration relative to Lambda function execution time
Tahmini Süre:1m 30s
Bu soruyu puanla