douwei8295 2019-05-01 01:26
浏览 45
已采纳

如何在SNS HTTPS订阅终结点中访问消息属性

I'm setting up an integration test to determine if a program that publishes a message to SNS is working correctly. The published message includes a few critical message attributes that I need to check in order to determine correctness.

So far, I have set up a simple HTTP server that acts as an SNS subscriber. The server correctly confirms its subscription and even receives messages from the topic, however I am at a loss as to how to access the attributes of these messages.

It should be mentioned that I am using ngrok to expose my host to SNS. To accomplish this, I'm using the command:

ngrok http 8080

When I create the subscription, I have made sure to enable raw message delivery:

subOut, err := snsCli.Subscribe(&sns.SubscribeInput{
    Endpoint: &ngrokURL,
    Attributes: map[string]*string{
        "RawMessageDelivery": aws.String("True"),
    },
    Protocol: aws.String("https"),
    TopicArn: aws.String(topicArn),
})

Note: I have also tried setting "RawMessageDelivery" to "true" instead of "True." This does not seem to elicit any changes.

I have also tried using the http protocol instead of https but have achieved the same results.

Below is the Notification post request received by the endpoint (I have substituted ARNs with asterisks):

POST / HTTP/1.1
x-amz-sns-message-type: Notification
x-amz-sns-message-id: c8bce1ed-3766-5a04-a9ad-b4afc662cc31
x-amz-sns-topic-arn: ****
x-amz-sns-subscription-arn: ****
x-amz-sns-rawdelivery: true
Content-Length: 1
Content-Type: text/plain; charset=UTF-8
Host: ****.ngrok.io
User-Agent: Amazon Simple Notification Service Agent
Accept-Encoding: gzip,deflate
X-Forwarded-Proto: https
X-Forwarded-For: 54.240.230.176

The messages published to SNS have only one byte in their body (a single space character) - I assume this is why the content length is 1.

One of the message attributes is of binary format and contains characters that are not allowed in the body of an SNS message, otherwise I would simply place the encoded attributes in the message body.

There do not appear to be any attributes available in the request, and I am totally stumped as to why. I would expect that they would be part of the raw request's body, but this does not seem to be the case. Any ideas?

EDIT: I should probably add that I have added an SQS subscriber to this same topic and that the SQS subscriber receives message attributes as would be expected.

  • 写回答

1条回答 默认 最新

  • dongzhang8475 2019-05-02 18:28
    关注

    The solution is as simple as disabling RawMessageDelivery. It would seem as though this option is required for delivering message attributes to an SQS endpoint but must not be used when delivering to an HTTP/S endpoint.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?