AWS SNS how to add line breaks in message

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 04:57:46

问题


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!


回答1:


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.




回答2:


This worked out for me:

"first line
second line"



回答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 .



来源:https://stackoverflow.com/questions/44787953/aws-sns-how-to-add-line-breaks-in-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!