Skip to main content

sqs-partial-batch-failure

Middleware for handling partially failed SQS batches.

Install

To install this middleware you can use NPM:

npm install --save @middy/sqs-partial-batch-failure
# Required for types only
npm install --save-dev @aws-sdk/client-sqs

Options

  • logger (function) (optional): A function that will be called when a record fails to be processed. Default: console.error

Sample usage

import middy from '@middy/core'
import sqsBatch from '@middy/sqs-partial-batch-failure'

const lambdaHandler = (event, context) => {
const recordPromises = event.Records.map(async (record, index) => {
/* Custom message processing logic */
return record
})
return Promise.allSettled(recordPromises)
}

export const handler = middy().use(sqsBatch()).handler(lambdaHandler)

Important

The value ReportBatchItemFailures must be added to your Lambda's FunctionResponseTypes in the EventSourceMapping. See Reporting batch item failures and Lambda EventSourceMapping