如何在 AWS CLI SNS 消息中提供 JSON?

How to provide JSON inside AWS CLI SNS message?

如何在命令行中通过 aws cli 精确的 JSON 结构发送(不是通过文件):

aws sns publish --topic-arn "arn:aws:sns:us-east-1:12345:myproject_serverlessscheduler_sns" --message '{"key1":"value1", "key2":"value2"}' --profile myprofile

以上是直接在命令行中提供的 JSON 的正确结构吗?

您提供的 JSON 结构是在 AWS CLI 中为 SNS 传递 JSON 的正确方法。

我在我的测试环境中进行了测试,如下所示,并确认可以 100% 工作:

使用 --message-structure json 参数集:

使用 Windows AWS CLI 测试:

aws sns publish --topic-arn "arn:aws:sns:eu-west-2:123412341234:some-topic" --message-structure json --message '{\"default\":\"This is the default Message\",\"sqs\": \"value\"}'

Json消息格式如下:

{
    "default": "A message.",
    "email": "A message for email.",
    "email-json": "A message for email (JSON).",
    "http": "A message for HTTP.",
    "https": "A message for HTTPS.",
    "sqs": "A message for Amazon SQS."
}

https://docs.aws.amazon.com/sns/latest/api/API_Publish.html#API_Publish_Examples