-
Notifications
You must be signed in to change notification settings - Fork 175
Description
Use case
When handling events from SQS and failing a message, not all errors are the same. E.g. if the event fails validation, then no amount of retrying will get it to pass. But throwing an error for it will lead to retrying the error like any other.
Instead, the event should end up directly on the SQS queues DLQ so that I can inspect and potentially redrive it without getting my logs spammed with errors from the retries.
Solution/User Experience
import {
SQSBatchProcessor,
EventType,
processPartialResponse,
NonRetriableError,
} from '@aws-lambda-powertools/batch';
import type { SQSHandler, SQSRecord } from 'aws-lambda';
const processor = new SQSBatchProcessor({ dlqUrl: process.env.DLQ_URL });
const recordHandler = async (record: SQSRecord): Promise<void> => {
throw new NonRetriableError();
};
export const handler: SQSHandler = async (event, context) =>
processPartialResponse(event, recordHandler, processor, {
context,
});
The processor needs to be configured with the DLQ url so it can send messages there. This also avoids any breaking change (even though just defining our own NonRetriableError should be enough already for this). It's a bit weird to add options to BatchProcessor as these options are specific just for the SQS type (though theoretically this might even make sense for other event sources).
Alternative solutions
Currently, I'm just accepting that my logs will get spammed in case of one of these errors.
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status