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
Author Info:

Rakesh (He/Him) has over 14+ 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 | Sitemap