Publish JSON Message to AWS SNS Topic via CLI Example

Help Save Code2care! 😢

I've lost 99% of my revenue to AdBlockers & AI. Your support could be the lifeline that keeps this passion project alive!

Buy Code2care a Coffee QR Code

Scan to Buy Me A Coffee and help me continue coding for you!


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

You can download this article in various formats for your convenience. Choose from the options below:

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

Author Info:

Rakesh (He/Him) has a Masters Degree in Computer Science with over 15+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright Code2care © 2024 | Privacy Policy | About Us | Contact Us | Search