Non-retryable error handler for @driimus/lambda-batch-processor
that sends corresponding SQS messages to a dead-letter SQS queue.
[!WARNING] This is an ES only package. Before installing, make sure that your project's configuration supports ECMAScript modules.
pnpm add @driimus/lambda-batch-processor @driimus/sqs-permanent-failure-dlq @aws-sdk/client-sqs
For types to work as expected, @types/aws-lambda
must be installed:
pnpm add --save-dev @types/aws-lambda
import { SQSBatchProcessor } from '@driimus/lambda-batch-processor';
import { PermanentFailureDLQHandler } from '@driimus/sqs-permanent-failure-dlq';
const queueUrl = 'https://queue.amazonaws.com/80398EXAMPLE/MyQueue'; // your queue url
const processor = new SQSBatchProcessor(
async (record) => {
/** do stuff */
},
{
nonRetryableErrorHandler: new PermanentFailureDLQHandler(queueUrl),
},
);
export const handler = processor.process;
By default, every instance of the handler will instantiate a new SQS client. It is possible to provide a custom client, which is especially helpful in scenarios where additional instrumentation is required, or you need to reuse the client elsewhere.
import { SQSClient } from '@aws-sdk/client-sqs';
import { PermanentFailureDLQHandler } from '@driimus/sqs-permanent-failure-dlq';
const sqs = new SQSClient({
/** custom config */
});
const queueUrl = 'https://queue.amazonaws.com/80398EXAMPLE/MyQueue'; // your queue url
const nonRetryableErrorHandler = new PermanentFailureDLQHandler(queueUrl, sqs);