DVA-C02 Question 196
Single answerYou are developing a serverless application using AWS Lambda. The Lambda function processes messages from an Amazon SQS queue and saves the results to a DynamoDB table. While testing, you notice that some messages are not being processed successfully and are being lost. What is the best way to ensure no messages are lost and failed messages are reprocessed?
- A
Configure a dead-letter queue (DLQ) for the Lambda function to capture failed messages.
- B
Increase the Lambda function's memory allocation to handle larger payloads.
- C
Enable long polling on the SQS queue to improve message reliability.
- D
Implement error handling within the Lambda function and retry logic for failed messages.
Show answer and explanation
Correct answer: A
Explanation
To ensure no messages are lost, you should configure a dead-letter queue (DLQ) for the Lambda function. The DLQ will store failed messages, allowing you to analyze and reprocess them later. This approach is the most reliable way to handle message failure in a serverless application using SQS and Lambda.
- A. Correct.
Configuring a dead-letter queue (DLQ) for the Lambda function ensures that any messages that fail to process are captured for later analysis or reprocessing, preventing data loss.
- B. Incorrect.
Increasing the Lambda function's memory allocation may improve performance but does not directly address the issue of failed message processing or prevent message loss.
- C. Incorrect.
Enabling long polling on the SQS queue reduces API requests and improves efficiency but does not ensure failed messages are captured or reprocessed.
- D. Incorrect.
Implementing error handling and retry logic in the Lambda function can improve reliability but does not provide a mechanism to capture permanently failed messages.