Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@middy/sqs-partial-batch-failure

1.0.0 • Public • Published

Middy sqs partial batch failure middleware

Middy logo

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

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

  • sqs: an AWS.SQS instance for deleting successfully processed messages from the queue.

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

Install

npm i @middy/sqs-partial-batch-failure

DownloadsWeekly Downloads

627

Version

1.0.0

License

MIT

Unpacked Size

11.3 kB

Total Files

8

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar