I recently implemented DLQ(Dead Letter Queue) for SQS. I have done the following three configurations.
- Default visibility timeout in SQS.
- In the Dead Letter Queue configuration, enable and Maximum receives are configured as 3.
- In Lambda configuration, Report batch item failures are enabled.
But the problem, all success/failure messages are processed three times and moved to DLQ.
For success cases, the correct JSON response is returned.
Once I disable the "Report batch item failures is enabled", message will deleted for both success/failure cases.
2
Answers
Once we enable the "Report batch item failures is enabled", we should change the response type of the function.
Old Code :
public async Task<String> FunctionHandlerAsync(SQSEvent sqsEvent)
New Code :
public async Task<SQSBatchResponse> FunctionHandlerAsync(SQSEvent sqsEvent)
Due to response type changes, we should change the code in function implementation.
create the object,
For exception cases,
Finally, return the batch response to function,
After the above changes, success messages are correctly deleted.
Reference: https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting
There are two immediate solutions that I could think help you debug your challenge:
More Tips: