Neurological Phenomenon Multiplexer

    @middy/sqs-partial-batch-failure
    TypeScript icon, indicating that this package has built-in type declarations

    3.0.3 • 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

    npm version npm install size GitHub Actions CI status badge
    Standard Code Style Known Vulnerabilities Language grade: JavaScript Core Infrastructure Initiative (CII) Best Practices
    Chat on Gitter Ask questions on StackOverflow

    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) (default console.error) - a logging function that is invoked with the current error as an argument. You can pass false if you don't want the logging to happen.

    NOTES:

    • Include the value ReportBatchItemFailures in the Lambda FunctionResponseTypes 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.

    FOSSA Status

    Install

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

    Homepage

    middy.js.org

    DownloadsWeekly Downloads

    8,473

    Version

    3.0.3

    License

    MIT

    Unpacked Size

    9.18 kB

    Total Files

    6

    Last publish

    Collaborators

    • lmammino
    • middyjs
    • willfarrell