Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @middy/sqs-partial-batch-failure with all npm packages installed. Try it out:

require("@middy/core/package.json"); // @middy/core is a peer dependency. require("aws-sdk/package.json"); // aws-sdk is a peer dependency. var sqsPartialBatchFailure = require("@middy/sqs-partial-batch-failure")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@middy/sqs-partial-batch-failure v1.1.0

SQS partial batch failure middleware for the middy framework

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

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free