Middy SQS partial batch failure middleware
SQS batch middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda
You can read the documentation at: https://middy.js.org/docs/middlewares/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
Options
-
logger
(function) (defaultconsole.error
) - a logging function that is invoked with the current error as an argument. You can passfalse
if you don't want the logging to happen.
NOTES:
- Include the value
ReportBatchItemFailures
in the LambdaFunctionResponseTypes
list - If you're using this feature with a FIFO queue, your function should stop processing messages after the first failure and return all failed and unprocessed messages. This helps preserve the ordering of messages in your queue.
Sample usage
import middy from '@middy/core'
import sqsPartialBatchFailureMiddleware from '@middy/sqs-partial-batch-failure'
const lambdaHandler = (event, context) => {
if (event.Event === 's3:TestEvent') {
console.log('s3:TestEvent')
return null
}
const recordPromises = event.Records.map(async (record, index) => {
/* Custom message processing logic */
})
return Promise.allSettled(recordPromises)
}
const handler = middy(lambdaHandler)
.use(sqsPartialBatchFailureMiddleware())
Middy documentation and examples
For more documentation and examples, refers to the main Middy monorepo on GitHub or Middy official website.
Contributing
Everyone is very welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.
License
Licensed under MIT License. Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the Middy team.