Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS SNS message lifetime

I have a use case where I need Amazon SNS to send a notification until my application (let's call it APP) has successfully received it, but the documentation says that the maximum lifetime of a message can be 1 hour.

Let's say that the APP crashes and it's not possible to get it live in 1 hour. I still need to somehow receive these messages.

There are multiple ways to implement it:

  1. APP polls from SQS. I do not like this option because it produces too much network traffic between APP and AWS.
  2. SNS sends a notification to both: APP and SQS. If APP is able to receive the message it will instantly remove it from the SQS. If the APP is not able to receive the message (crashed), it can load the messages from SQS on startup and clean the queue.
  3. AWS Lambda code as messaging service. If Lambda code fails it can push the message to SQS Dead Letter Queue, otherwise keeps the queue clean. Handling Lamba code updates is too much overhead, would be cool to solve this problem with pure AWS if possible.

The perfect solution would be to set endless timeout for SNS message, but looks like Amazon does not support it.

What do you think is the best solution to solve this problem? Have I missed something?

like image 552
Madis Pukkonen Avatar asked Jan 13 '17 09:01

Madis Pukkonen


1 Answers

One option might be to have SNS deliver messages to a Lambda that calls your app. If the Lambda can't deliver the message to your app then fail so that SNS will retry the Lambda. You can then configure your Lambda with a dead letter queue (SQS) so that if it fails too many times the message will go onto the queue. Finally you can have another Lambda running on a schedule that checks the dead letter queue and retries the Lambda invocation. It would just keep putting the message back onto the dead letter queue if it fails.

This way if your app is available the message would be delivered immediately. If the app isn't available then it would retry delivery later.

like image 109
Rich Buggy Avatar answered Oct 13 '22 21:10

Rich Buggy