Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS SNS how to add line breaks in message

I'm trying to send SNS messages via CLI in json format.

aws sns publish --cli-input-json "{\"TopicArn\":\"xxx\",\"Message\":\"first line\n second line\",\"Subject\":\"Empty subject\"}"

But the \n doesn't work. Neither is "\r\n" or "\n". I think the string is escaped by SNS so \n doesn't work. Does anyone know how to send a message of 2 lines?(Sending 2 messages is not an option) Appreciate your advice!

like image 360
OrlandoL Avatar asked Jun 27 '17 19:06

OrlandoL


People also ask

How do I post a SNS message?

Sign in to the Amazon SNS console . In the left navigation pane, choose Topics. On the Topics page, select a topic, and then choose Publish message. The console opens the Publish message to topic page.

How long do messages stay in AWS SNS?

In order to allow you to build great applications that behave well in an environment with real-time information and intermittent connections, Amazon SNS now allows you to set a TTL (Time to Live) value of up to two weeks for each message.

What is the format of an SNS endpoint message and what are its properties?

HTTP/HTTPS notification JSON format When Amazon SNS sends a notification to a subscribed HTTP or HTTPS endpoint, the POST message sent to the endpoint has a message body that contains a JSON document with the following name-value pairs. The Message value specified when the notification was published to the topic.


2 Answers

I think \\n is actually what you are looking for. I've just tested it by sending push notifications to my device through AWS SNS.

So your message should look like this:

aws sns publish --cli-input-json "{\"TopicArn\":\"xxx\",\"Message\":\"first line\\nsecond line\",\"Subject\":\"Empty subject\"}"

Note, you should not leave the white space after the line break symbol, otherwise, your new line would start with that space.

like image 67
Matěj Zmítko Avatar answered Oct 27 '22 01:10

Matěj Zmítko


aws sns publish --topic-arn "arn:aws:sns:us-west-2:0123456789012:my-topic" --message file://message.txt

message.txt is a text file containing the message to publish:

Hello World Second Line

Putting the message in a text file allows you to include line breaks .

like image 38
DallasRaycom Inc Accounts Avatar answered Oct 27 '22 01:10

DallasRaycom Inc Accounts