2

I have a AWS lambda function written in javascript using the node12 runtime. If I fail to process the message given in the sqs event, how do I tell the queue that I was unable to process the message and to leave the message in the queue?

Does it require an http response with status code like 200 for success or 500 for failure, or does the lambda need to throw an error to signal that it didn't process.

I can't find what response is expected in an sqs event handler function. What is the handler expected to return?

async function handler(event) {
    try {
        const body = event.Records[0].body;
        // do some process 
        // what do I return if successful
    } catch (err) {
        // what do I return if my process wasn't successful
    }
}
skellertor
  • 916
  • 1
  • 9
  • 26

1 Answers1

2

This simple answer is that you and throw an error and it will consider it failed. Of course then lambda retry logic starts to kick in, so you need to understand that as well. This page talks about error handling in lambda, and gives a pretty good breakdown of the different scenarios.

Jason Wadsworth
  • 8,059
  • 19
  • 32
  • To extend the accepted answer: Optionally you can specify which of the received batch of events failed. See https://stackoverflow.com/a/70725725/784889 – KonstantinK Mar 15 '23 at 19:49