Closed
Description
Expected Behavior
When a SQS record that failed in a previous Lambda invocation is retried and handled by the same Lambda instance again, it should be processed by the provided recordHandler
Current Behavior
When a SQS record that failed in a previous Lambda batch invocation is retried and handled by the same Lambda instance again, it is skipped and returned as a failure without going through the recordHandler
.
Only if the record is handled by a concurrent Lambda instance will it be processed again.
Code snippet
import { processPartialResponse, SqsFifoPartialProcessorAsync } from "@aws-lambda-powertools/batch";
import { SQSHandler, SQSRecord } from "aws-lambda";
const processor = new SqsFifoPartialProcessorAsync();
const recordHandler = async (record: SQSRecord): Promise<void> => {
console.debug("RECORD HANDLER INVOKED");
throw new Error("Random error occurred");
};
export const handle: SQSHandler = async (event, context) => {
console.debug('SQS HANDLER INVOKED');
return processPartialResponse(event, recordHandler, processor, {
context,
skipGroupOnError: true,
throwOnFullBatchFailure: false,
});
};
Steps to Reproduce
- Set up a FIFO queue, a DLQ and a Lambda with the above handler code and set reserved concurrency to 0
- Publish any message to the queue
- In the logs you should observe
SQS HANDLER INVOKED
andRECORD HANDLER INVOKED
for the first invocation, and after the visibility timeout it will only logSQS HANDLER INVOKED
for follow-up invocations, untilmaxReceiveCount
is hit and the message is moved to the DLQ
Possible Solution
In SqsProcessor
, the failedGroupIds
should be cleared after each Lambda invocation.
Introduce a method to clear the failedGroupIds
in SqsProcesor
.
In SqsFifoPartialProcessorAsync
override the prepare
method and add a call to clear failedGroupIds
.
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
18.x
Packaging format used
npm
Execution logs
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Shipped