6

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!

OrlandoL
  • 838
  • 1
  • 11
  • 29
  • Can you enclose it with single quote and try? `\"first line'\n' second line\"` – helloV Jun 27 '17 at 19:15
  • No single quotes don't work :) – OrlandoL Jun 27 '17 at 20:33
  • Your CLI command works perfectly without any change. I just sent an SNS and see two lines in my email. What shell are you using? – helloV Jun 27 '17 at 20:42
  • helloV thanks for pointing that out! Actually I invoked the command in the string format, in a minor language that few people use. In that case I must have made a mistake in how to escape within the string. – OrlandoL Jun 27 '17 at 20:50

4 Answers4

4

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.

Matěj Zmítko
  • 257
  • 1
  • 6
  • 21
3

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 .

1

This worked out for me:

"first line
second line"
Felipe
  • 21
  • 3
0

four backslash works for me

using Aws SNS with Firebase

EX: backslashbackslashbackslashbackslash+n

Anand Atul
  • 11
  • 2