endless dead letter queue (DLQ) processing when Middy.js SQS queue validator fails

180 Views Asked by At

I've got a lambda handler that processes incoming SQS events. There is a middyJs handler with a validator middleware on top of that. When MiddyJs validation fails the event gets stuck in an endless loop inside DLQ.
When I throw an Error intentionally inside the handler it appears on DLQ just once. but with MiddyJs validation, it'll run through an endless loop.
Does anyone know what might cause this behavior?

The middy configuration is as follows:

middy(
  sqsEventLambdaHandler,
)
  .use(eventNormalizerMiddleware())
  .use(
    validator({
      eventSchema: transpileSchema(sqsEventLambdaEventSchema),
    }),
  )
  .use(sqsPartialBatchFailure());

And here is the error from cloudwatch:

Unknown application error occurred
Runtime.Unknown
1

There are 1 best solutions below

4
will Farrell On

@middy/sqs-partial-batch-failure is designed to work with a specific SQS configuration.

The value ReportBatchItemFailures must be added to your Lambda's FunctionResponseTypes in the EventSourceMapping.

https://middy.js.org/docs/middlewares/sqs-partial-batch-failure#important