Q59 — AWS DVA-C02 Ch.3
Question 59 of 100 | ← Chapter 3
A company has an AWS Lambda function that uses the Amazon SQS API to read messages from an Amazon Simple Queue Service (Amazon SQS) queue. Due to random failures of a downstream dependency, the Lambda function fails to process all messages successfully. The developer needs to enhance the reliability of the Lambda function so that it can successfully process each message even when the downstream dependency fails. Which solution requires the least effort to meet this requirement?
- A. Move the calls to the third-party dependency into an exception-handling block. If a failure in the third-party dependency is caught in the exception handler, write the message back to the SQS queue.
- B. Update the code in the Lambda function to remove the call to the SQS SDK ReceiveMessage function. Configure the Lambda function to use the SQS queue as an event source. Set the maxReceiveCount value of the SQS queue's redrive policy to at least 5.
- C. Create a second SQS queue to serve 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 serve as a dead-letter queue. Move the calls to the third-party dependency into an exception-handling block. If a failure in the third-party dependency is caught in the exception handler, write the message to the dead-letter queue. ✓
Correct Answer: D. Create a second SQS queue to serve as a dead-letter queue. Move the calls to the third-party dependency into an exception-handling block. If a failure in the third-party dependency is caught in the exception handler, write the message to the dead-letter queue.
Explanation
To improve the reliability of the Lambda function with minimal effort and ensure messages are processed successfully even when third-party dependencies fail, the best practice is to combine exception handling with a dead-letter queue. Option D satisfies both conditions: first, it places calls to the third-party dependency inside an exception-handling block to catch failures; second, it writes failed messages to a dead-letter queue, ensuring messages are not lost and can be retried or analyzed later. This approach guarantees message reliability while simplifying code logic, making it the optimal choice. 【Lantern Certification provided by: swufelp1999】