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?
- Increase the visibility timeout of the Amazon SQS queue to be at least six times the timeout of the AWS Lambda function.Cevap
- BDecrease 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.
- CModify 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.
- DStore 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
Anahtar Kavram
SQS visibility timeout configuration relative to Lambda function execution time
Tahmini Süre:1m 30s