Reputation: 894
I have a Lambda function, which will be sending SNS notification when a message is sent to SQS Queue. But i observe that Lambda will delete the message from queue once it has processed it and its been mentioned here
Is there a way i can make the lambda fail, without actually throwing a new Exception in java.
Upvotes: 7
Views: 6698
Reputation: 406
By default, SQS to Lambda integration means that messages in que will become invisible once the function begins processing it, and will be deleted from the que once the function has completed.
If the function fails (bad exit), then the message will go back to 'visible', and will be processed once again by a new lambda invocation. This will go-on until whatever is configured in your re-drive policy.
In any case, after about 4 days, messages will start to be purged off the que, the SQS que is not a permanent storage place. You cannot use SQS as permanent storage.
A short answer to your question is to fail the invocation by exiting with a non-zero status -- but beware, the message will be reprocessed, unless you have a redrive policy that will push it into the DLQ.
Upvotes: 4
Reputation: 238051
From you description, it seems that you should consider using fan-out scenario for your use-case:
The "fanout" scenario is when an Amazon SNS message is sent to a topic and then replicated and pushed to multiple Amazon SQS queues, HTTP endpoints, or email addresses.
In this scenario, your SNS would publish a message to two SQS queues. Subsequently, each team would have its own messages to work, and you wouldn't need to forcefully terminate your lambda to keep a processed message in a single queue.
Upvotes: 4