@driimus/sqs-permanent-failure-dlq
v0.2.1
Published
Send SQS messages causing non-retryable errors to a dead-letter SQS queue
Downloads
18
Maintainers
Readme
@driimus/sqs-permanent-failure-dlq
Non-retryable error handler for @driimus/lambda-batch-processor
that sends corresponding SQS messages to a dead-letter SQS queue.
Installation
[!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
Type hints
For types to work as expected, @types/aws-lambda
must be installed:
pnpm add --save-dev @types/aws-lambda
Usage
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;
Custom SQS Client
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);