Q66 — AWS SAA-C03 Ch.17

Question 66 of 89 | ← Chapter 17

Q1366. A solutions architect has an application container, an AWS Lambda function, and an 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(ML) 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 solutions architect has noticed that the Lambda function sometimes processes duplicate messages from the SQS queue. What should the solutions architect do to ensure that the Lambda function does not process duplicate messages?

Correct Answer: D. Configure the SQS queue's visibility timeout value to be greater than the maximum time it takes to call the third-party API.

Explanation

The correct answer is D. Configure the SQS queue's visibility timeout value to be greater than the maximum time it takes to call the third-party API.Explanation:The problem arises because the Lambda function sometimes processes duplicate messages from the SQS queue. This happens when:The Lambda function is invoked by an SQS message.The Lambda function takes too long to process the message (e.g., waiting for a slow third-party API response).If the Lambda function does not delete the message from the queue before the SQS visibility timeout expires, the message becomes visible again and can be processed by another Lambda invocation (leading to duplicates).Why Option D is the Best Choice:SQS Visibility TimeoutDetermines how long a message is hidden from other consumers after being picked up by a Lambda function.If the Lambda function does not delete the message before the visibility timeout expires, SQS assumes the processing failed and makes the message visible again (causing duplicates). Solution: Set the visibility timeout longer than the maximum processing time (including the 60-second API call + Lambda execution time).Example: If the API takes 60 seconds and Lambda takes 5 seconds, set visibility timeout to 65+ seconds (e.g., 70 seconds).Prevents Duplicate ProcessingEnsures the message stays hidden until the Lambda function has a chance to complete processing and delete it.Why Other Options Are Incorrect:A. Configure the Lambda function with a larger amount of memory Does not solve the duplicate issue Memory affects performance but not message visibility.Irrelevant to SQS message redelivery logic.B. Configure an increase in the Lambda function's timeout value Partial solution, but not sufficient aloneIf the Lambda timeout is increased but the SQS visibility timeout remains short, the message may still reappear before Lambda finishes.Both Lambda timeout and SQS visibility timeout should be aligned, but SQS visibility timeout is the critical factor here.C. Configure the SQS queue's delivery delay value to be greater than the maximum API call time Misunderstands the purpose of delivery delayDelivery delay controls how long to wait before making a message available after it is sent to the queue. It does not affect visibility after a message is picked up by a consumer.Best Practices for Avoiding Duplicates:Set SQS visibility timeout > Lambda execution time + API call time (e.g., 70 seconds in this case). Ensure Lambda deletes the message from SQS after successful processing (using DeleteMessage API). Consider using SQS Dead-Letter Queues (DLQ) for messages that fail repeatedly (to avoid infinite retries).Conclusion:Option D is the correct solution because adjusting the SQS visibility timeout ensures messages stay hidden long enough for Lambda to process them without reappearing.Avoid Options A, B, and C (they do not address the root cause of duplicate processing).Final Answer: D