How to test AWS SNS locally?

柔情痞子 提交于 2019-12-04 19:58:39

问题


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?


回答1:


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.




回答2:


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



回答3:


I like ngrok but you pay to have a fixed external address, if you want to do it for free you could use a spare email account inbox to send Email-JSON sns. Then an IMAP library to access it, read the emails and pipe the data.



来源:https://stackoverflow.com/questions/42578215/how-to-test-aws-sns-locally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!