Publish JSON Message to AWS SNS Topic via CLI Example



If you want to publish a JSON Message to an AWS SNS Topic via the AWS CLI, you can make use of the aws sns publish command and pass the JSON string to the --message option.

Syntax:

aws sns publish --topic-arn topic-arn --message '{"json-key1": "json-value1", "json-key2": "json-value2"}'

Let's take a look at an example.

aws sns publish 
   --topic-arn arn:aws:sns:us-east-1:107xx89xx9xx:smsTopic 
   --message '{"type": "error", "message": "Error code 202 - Validation failed"}'

-------------------------------------------------------
|                       Publish                       |
+-----------+-----------------------------------------+
|  MessageId|  1xx99788-8cxx-5bcd-8ff3-caxxf6b175xx   |
+-----------+-----------------------------------------+
Publish JSON Message Example AWS SNS CLI
-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap