Publish to SNS topic using curl

0

Is it possible to post (publish) to an SNS topic using a simple curl command from a shell in an EC2 instance?

Something like this:

curl -d "Test message" https://sns.us-west-2.amazonaws.com/?Action=Publish&TargetArn=arn%3Aaws%3Asns%3Aus-west-2%3A803981987763%3Aendpoint

I've tried various combinations, and the closest I get is port 443 connection error. Does SNS use a different port number? I've not found any actual example of this, not sure it's supposed to work.

Rich650
질문됨 5년 전2162회 조회
1개 답변
0

Hi, in a nutshell, yes it is possible... but requires re-architecting to:
curl --> API Gateway --> SNS

Review the following Link: https://www.alexdebrie.com/posts/aws-api-gateway-service-proxy/
Here are the steps outlined in the link above

We created an SNS topic to receive messages and set up a subscription on that topic to forward all messages to a cell phone.

We set up our basic API Gateway resources, including a REST API, a resource (/ingest) and a method (POST) on that resource.

We made an IAM role that could be assumed by API Gateway and gave permission to publish messages to our SNS topic.

We configured an integration to our SNS topic from our REST API’s resource and method. This integration included a request mapping template, a response mapping template, and a method response.

We deployed our REST API to make it live, then sent an HTTP request using curl. We received the message on our cell phone, indicating that it was successfully published to our SNS topic.

Hope this helps.
-randy

전문가
답변함 5년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠