Skip to content

Feature request: In Batch Processing, allow sending requests directly to DLQ #4478

@dbartholomae

Description

@dbartholomae

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

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    batchThis item relates to the Batch Processing Utilityfeature-requestThis item refers to a feature request for an existing or new utilityneed-customer-feedbackRequires more customers feedback before making or revisiting a decision

    Type

    No type

    Projects

    Status

    Ideas

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions