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.

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

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗