Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test AWS SNS locally?

I want to use Amazon SNS service. And I want to have an ability to subscribe an http rest to SNS topic to receive notifications.

However locally my application has URL as localhost So it's impossible for me to test application behavior locally.

I found one article about using ngrok server, to use some public IP instead of local.

However it doesn't seem to be a good solution for me.

Do you have any ideas how I could have a working SNS subscriber locally?

like image 393
Kiryl Avatar asked Mar 03 '17 11:03

Kiryl


People also ask

Can you use SNS without SQS?

SNS supports several end points such as email, SMS, HTTP end point and SQS. If you want unknown number and type of subscribers to receive messages, you need SNS. You don't have to couple SNS and SQS always. You can have SNS send messages to email, SMS or HTTP end point apart from SQS.

How do you test SNS SQS?

Sign in to the Amazon SQS console . Select the queue that has a pending subscription to the topic. Choose Queue Actions, View/Delete Messages and then choose Start Polling for Messages. A message with the subscription confirmation is received in the queue.

What is the difference between AWS SQS and SNS?

SQS queues and SNS topics offer different functionality, though both can publish to downstream Lambda functions. An SQS message is stored on the queue for up to 14 days until it is successfully processed by a subscriber. SNS does not retain messages so if there are no subscribers for a topic, the message is discarded.


Video Answer


2 Answers

You could also use ngrok to expose your localhost publicly.

They way it works is it creates a subdomain dynamically and tunnels all request to your machine on the desired port.

Picture this scenario, I have a nginx running on localhost:8080. I open my terminal and run ngrok 8080, it will take my terminal session and log my public url, like 'as78fh.ngrok.com'.

If I go on another computer, open the browser and navigate to as78fh.ngrok.com/register the request gets served from my localhost:8080/register through the tunnel back to the internet.

I use it for lots of tricky developments, like email webhooks, github integrations and, of course, amazon sns.

like image 85
Magus Avatar answered Oct 21 '22 12:10

Magus


Take a look at one of fake SNS implementations in GitHub, such as s12v/sns:

Fake Amazon Simple Notification Service (SNS) for testing. Supports:

  • Create/List/Delete topics
  • Subscribe endpoint
  • Publish message
  • Subscription persistence
  • Integrations with (Fake-)SQS, File, HTTP, RabbitMQ, Slack
like image 40
Olli Avatar answered Oct 21 '22 12:10

Olli