A Lambda function is triggered by an SQS queue and calls a third-party ML API that can take up to 60 seconds to respond. The Lambda timeout is 65 seconds. The developer sees the function sometimes processing duplicate SQS messages. What should the developer change so the function does not process duplicates?
Choose an answer
Tap an option to check your answer.
Correct answer: Set the SQS queue's visibility timeout to be greater than the third-party API's maximum response time..
Why this is the answer
The correct answer is to set the SQS queue's visibility timeout to be greater than the third-party API's maximum response time. When a Lambda function processes a message from an SQS queue, SQS makes the message invisible for a period defined by the visibility timeout. If the Lambda function successfully processes and deletes the message within this period, no duplicates occur. However, if the function takes longer than the visibility timeout to process the message (e.g., waiting for a slow API response) and doesn't delete it, the message becomes visible again and can be processed by another Lambda invocation, leading to duplicates. Increasing the visibility timeout ensures the message remains invisible until the Lambda function has enough time to complete processing and delete it. Increasing Lambda memory allocation might speed up the function but doesn't directly address the visibility timeout issue. Increasing the Lambda timeout setting is already sufficient at 65 seconds for a 60-second API call and doesn't solve the SQS visibility problem. Setting the SQS delivery delay affects when a message first becomes available in the queue, not how long it remains invisible after being picked up.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed