DVA-C02 · Question #544
A developer has an application container, an AWS Lambda function, and an Amazon Simple Queue Service (Amazon SQS) queue. The Lambda function uses the SQS queue as an event source. The Lambda function
The correct answer is D. Configure the SQS queue's visibility timeout value to be greater than the maximum time it takes to. SQS visibility timeout controls how long a message remains hidden after being received; if the Lambda function takes longer than the visibility timeout, SQS makes the message visible again, causing duplicate processing.
Question
A developer has an application container, an AWS Lambda function, and an Amazon Simple Queue Service (Amazon SQS) queue. The Lambda function uses the SQS queue as an event source. The Lambda function makes a call to a third-party machine learning API when the function is invoked. The response from the third-party API can take up to 60 seconds to return. The Lambda function's timeout value is currently 65 seconds. The developer has noticed that the Lambda function sometimes processes duplicate messages from the SQS queue. What should the developer do to ensure that the Lambda function does not process duplicate messages?
Options
- AConfigure the Lambda function with a larger amount of memory.
- BConfigure an increase in the Lambda function's timeout value.
- CConfigure the SQS queue's delivery delay value to be greater than the maximum time it takes to
- DConfigure the SQS queue's visibility timeout value to be greater than the maximum time it takes to
How the community answered
(49 responses)- A14% (7)
- B4% (2)
- C27% (13)
- D55% (27)
Why each option
SQS visibility timeout controls how long a message remains hidden after being received; if the Lambda function takes longer than the visibility timeout, SQS makes the message visible again, causing duplicate processing.
Increasing memory allocation affects CPU speed and memory limits, not message visibility or duplicate delivery behavior.
The function timeout is already 65 seconds, and increasing it further does not prevent SQS from re-delivering a message when the visibility timeout is shorter than processing time.
Delivery delay postpones when a newly added message first becomes available; it does not affect the re-delivery of messages already in flight.
When Lambda retrieves an SQS message, the message becomes invisible for the duration of the visibility timeout. If the Lambda function (which can take up to 60 seconds) does not finish before the visibility timeout expires, SQS re-queues the message for another invocation. Setting the visibility timeout greater than 65 seconds prevents the message from reappearing before processing completes.
Concept tested: SQS visibility timeout and duplicate message prevention
Source: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html
Community Discussion
No community discussion yet for this question.