Middy sqs partial batch failure middleware

Middy logo

SQS batch middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda

npm version Known Vulnerabilities Standard Code Style Greenkeeper badge Chat on Gitter

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

Sample usage

const middy = require('@middy/core')
const sqsBatch = require('@middy/sqs-partial-batch-failure')

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

const handler = middy(originalHandler)
  .use(sqsBatch())

Your Lambda function requires permission to delete the message from the queue.

{
  "Effect": "Allow",
  "Action": [
    "sqs:DeleteMessage"
  ],
  "Resource": "arn:aws:sqs..."
}

Usage with Node.js <= 10

This middleware expects a Promise.allSettled resolved value to be returned by the Lambda handler, which is only available in Node.js 12+.

To use this middleware with earlier versions of Node.js, use a polyfill. We recommend installing promise.allsettled and adding require('promise.allsettled').shim() to your handler.

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-2018 Luciano Mammino and the Middy team.

FOSSA Status