How could a SQS worker written with bref signal a retry?

258 Views Asked by At

After setting batchSize: 1 how should the worker indicate success and how should it indicate temporary failure / ask for a retry? I read https://docs.aws.amazon.com/lambda/latest/dg/invocation-retries.html but it obviously doesn't cover a custom runtime and it's not at all clear what's happening and it doesn't talk about SQS anyways. I suspect just throwing an exception might be enough but I can't make heads or tails as to what signals Lambda.

Tutorials like https://medium.com/cs-code/setup-queue-with-serverless-laravel-using-bref-92b2cd803bb7 make no mention of this. It talks about maxReceiveCount: 3 but not about how to make SQS retry later.

2

There are 2 best solutions below

0
On BEST ANSWER

According to the bref maintainer:

Hey, yes that's exactly that: throw an exception in the handler and let it bubble up to Bref (which will bubble up to Lambda and then SQS).

https://github.com/brefphp/bref/discussions/911

3
On

I am not sure about custom runtime but in Nodejs if you just throw an error the message is available back in SQS in case no error is thrown it is deleted from SQS.

Configure a dead letter queue for sqs after maxRetryCount, so your message will go to DLQ after retries. After fixing the cause of failures you can move the message from DLQ to your main SQS using another lambda or cli.

SQS will not retry itself as lambda do long polling from SQS.