AWS Certified Developer – Associate — Question 305
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?
Answer options
- A. Configure the Lambda function with a larger amount of memory.
- B. Configure an increase in the Lambda function's timeout value.
- C. Configure the SQS queue’s delivery delay value to be greater than the maximum time it takes to call the third-party API.
- D. Configure the SQS queue’s visibility timeout value to be greater than the maximum time it takes to call the third-party API.
Correct answer: D
Explanation
To prevent duplicate processing, the SQS queue's visibility timeout must be configured to be longer than the Lambda function's execution time, which is driven by the 60-second API call. If the visibility timeout is shorter than this duration, SQS will place the message back on the queue before the Lambda function finishes, causing another invocation to process it. Changing the Lambda timeout, increasing memory, or modifying the delivery delay will not address this visibility window issue.