如何从 API 网关集成请求向 SNS 发布添加消息属性

How to add Message Attributes to SNS Publish from API Gateway Integration Request

我可以使用 CLI 找到格式

aws sns publish --topic-arn arn:aws:sns:us-west-2:111111111111:test
    --message "Testing the CLI" 
    --subject "From the CLI" --message-attributes "{\"somename\":
        {\"DataType\":\"String\",\"StringValue\":\"somevalue\"}}"

但我无法找到(或弄清楚)的是如何从 API 网关上的集成请求执行此操作。

我认为它需要作为集成请求的查询参数来完成,但语法与为 SQS 添加消息属性不同。我按照以下示例使用参数命名符号对此进行了测试:

MessageBody=This+is+a+test+message
MessageAttribute.1.Name=test_attribute_name_1
MessageAttribute.1.Value.StringValue=test_attribute_value_1
MessageAttribute.1.Value.DataType=String

我也试过:

MessageAttributes   '{"store":{"DataType":"String","StringValue":"example_corp"}}'

到目前为止无法正常工作,非常感谢任何帮助。

在深入研究 AWS 文档后,我发现没有关于在 API 网关资源方法中将 SNS Publish MessageAttributes 设置为 URL 查询字符串参数的准确文档。

根据他们在此处给出的部分语法示例:https://docs.aws.amazon.com/sns/latest/api/API_Publish.html,然后我就可以向它扔东西直到卡住。

这是您需要使用的正确点符号语法和参数:

MessageAttributes.entry.1.Name = "Attribute1"
MessageAttributes.entry.1.Value.DataType = 'String'
MessageAttributes.entry.1.Value.StringValue = 'Test'

其中 "Name" 和 "DataType" 是必需的。

干杯!