0

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
Pouyan
  • 15
  • 5

1 Answers1

0

@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

will Farrell
  • 1,733
  • 1
  • 16
  • 21
  • I've added partial failure and it's working under normal circumstances. The problem is that it only doesn't work if I use middy middleware for validation. In this case, it'll go through an endless loop. – Pouyan Aug 30 '23 at 21:13
  • Sounds like `@middy/validator` is throwing a validation error causing the endless loop. Check the JSON Schema matches the input event. – will Farrell Aug 31 '23 at 13:57
  • Yes, that's exactly what I want to track! if the incoming event doesn't pass the schema validation I can track that by monitoring DLQ. What I did, was remove the validation middleware and call the validatore manually inside the handler. In this case, the failure won't cause a loop with an unknown error. let me know if you have a workaround to make it work with the middleware. – Pouyan Aug 31 '23 at 21:08
  • 1
    I pushed an update to the docs to warn others about this. And opened an issue https://github.com/middyjs/middy/issues/1095 – will Farrell Sep 01 '23 at 01:43