How to access message attributes in SNS HTTPS subscription endpoint

扶醉桌前 提交于 2019-12-11 10:52:50

问题


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:


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.



来源:https://stackoverflow.com/questions/55930596/how-to-access-message-attributes-in-sns-https-subscription-endpoint

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