简体   繁体   中英

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)

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 :

$ 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. 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. 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.

How can I solve this?

Solved. It was a IP resolving problem beacuse of Docker networking.

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 :

$ 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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