AWS Certified Developer – Associate — Question 202
A company has an AWS Lambda function that reads messages from an Amazon Simple Queue Service (Amazon SQS) queue by using the Amazon SQS API. The Lambda function is not processing all the messages successfully because of random failures of a third-party dependency. A developer needs to improve the reliability of the Lambda function so that the Lambda function will process each message successfully despite the failures of the third-party dependency.
Which solution will meet this requirement with the LEAST effort?
Answer options
- A. Move the call to the third-party dependency into an exception handling block. Write the message back to the SQS queue if a failure in the third-party dependency is caught in the exception handler.
- B. Update the code in the Lambda function to remove calls to the SQS SDK ReceiveMessage function. Configure the Lambda function to use the SQS queue as an event source. Set the maxReceiveCount value on the SQS queue's redrive policy to at least 5.
- C. Create a second SQS queue to use as a dead-letter queue. Configure a redrive policy on the original SQS queue to send failed messages to the dead-letter queue. Modify the Lambda function to read messages from both queues.
- D. Create a second SQS queue to use as a dead-letter queue. Move the call to the third-party dependency into an exception handling block. Write the message to the dead-letter queue if a failure in the third-party dependency is caught in the exception handler.
Correct answer: D
Explanation
Option D is correct because it allows for capturing failures in a structured manner by utilizing a dead-letter queue, which helps in isolating problematic messages without losing them. Option A does not provide a mechanism for tracking failures effectively, and simply retrying without a dead-letter approach could lead to message loss. Option B changes the message retrieval method but does not directly address the handling of failures from the third-party dependency. Option C, while it introduces a dead-letter queue, lacks the exception handling aspect that is crucial for managing dependency failures effectively.