I recently implemented DLQ(Dead Letter Queue) for SQS. I have done the following three configurations.
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.
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,
List<SQSBatchResponse.BatchItemFailure> batchItemFailures = new List<SQSBatchResponse.BatchItemFailure>();
For exception cases,
batchItemFailures.Add(new SQSBatchResponse.BatchItemFailure { ItemIdentifier = record.MessageId });
Finally, return the batch response to function,
return new SQSBatchResponse(batchItemFailures);
After the above changes, success messages are correctly deleted.
Reference: https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting