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

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!