简体   繁体   English

AWS SNS HTTP订阅未调用终端节点

[英]AWS SNS HTTP subscription is not calling endpoint

I have deployed AWS SNS using Localstack in my dev machine and now I'm trying to consume messages I'm emitting from awslocal CLI (basically it's a aws against my local Localstack infra) 我已经在开发人员计算机中使用Localstack部署了AWS SNS,现在我正尝试使用从awslocal CLI发出的消息(基本上是来自本地Localstack infra的aws

First, I have created a topic: 首先,我创建了一个主题:

$ awslocal sns create-topic --name my-topic

Then, I've created a HTTP subcription against http://localhost:8080/sns/publish : 然后,我针对http://localhost:8080/sns/publish创建了一个HTTP http://localhost:8080/sns/publish

$ awslocal sns subscribe --topic-arn "arn:aws:sns:us-east-1:123456789012:my-topic" --protocol http --notification-endpoint http://localhost:8080/sns/publish

I have a server running at localhost in port 8080 with a POST /sns/publish endpoint. 我有一台运行在localhost的服务器,端口为8080 ,带有POST /sns/publish端点。 It is supposed to be called in order to confirm the subscription. 应该调用它以确认订阅。 But it's never called. 但这从来没有。

I have some clues. 我有一些线索。 I have deployed Localstack using Docker. 我已经使用Docker部署了Localstack。 After checking the container logs, I have seen this error: 检查容器日志后,我看到了此错误:

2018-07-02T10:20:03:INFO:werkzeug: 127.0.0.1 - - [02/Jul/2018 10:20:03] "POST /sns/publish HTTP/1.1" 405 -

HTTP ERROR 405 corresponds to Method Not Allowed error so maybe it's trying to call a container endpoint instead of my host machine's endpoint. HTTP错误405对应于“方法不允许错误”,因此它可能正在尝试调用容器终结点而不是我的主机的终结点。

How can I solve this? 我该如何解决?

Solved. 解决了。 It was a IP resolving problem beacuse of Docker networking. 由于Docker网络,这是一个IP解决问题。

I've created a subnet: 我创建了一个子网:

docker network create -d bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 mynet

And subscribe SNS against 192.168.9.1 instead of localhost : 并针对192.168.9.1而不是localhost订阅SNS:

$ awslocal sns subscribe --topic-arn "arn:aws:sns:us-east-1:123456789012:my-topic" --protocol http --notification-endpoint http://192.168.0.1:8080/sns/publish

Done! 做完了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM