aws sns确认订阅请求处理问题 [英] aws sns confirm subscription request processing issue

查看:280
本文介绍了aws sns确认订阅请求处理问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为s3中的存储桶实施aws sns服务,我正在遵循此文档 https://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.html 据此,在确认订阅的请求中将有订阅URL,该订阅URL即将到达我们提供的URL,但是我在请求中接收到空的正文. 我试图记录尸体,但给了我一个空的物体.并尝试使用bodyparser,但结果相同.

I am trying to implement the aws sns service for a bucket in s3 and i am following this document https://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.html according to this there will be subscribe url in the request for the confirmation subscription which will be coming to the url that we provide, but i am receiving empty body in the request. I tried to log the body but gave me an empty object. and tried by using the bodyparser but same result.

这是我正在实施的路线.

here is my route that i am implementing.

 router.post("/s3FileCallback", function (req, res) {
      debugger;
      var bodyParser = require('body-parser');
      var app = express();
      app.use(bodyParser.urlencoded({ extended: false }));
      app.use(bodyParser.json())
      if (req.get("x-amz-sns-message-type") == "SubscriptionConfirmation") {
        console.log("arn" + req.get("x-amz-sns-topic-arn"));
        const subscribeUrl = req.body.SubscribeURL;
        console.log("subscribeUrl" + subscribeUrl);
})

有什么我想念的东西吗?谁能指出我的正确方向?

is there any thing i am missing. can any one point me in right direction please.

推荐答案

我发现了我所缺少的,

router.post('/s3FileCallback', function(req, res) {
    debugger;
    if (req.get('x-amz-sns-message-type') == 'SubscriptionConfirmation') {
        console.log('arn' + req.get('x-amz-sns-topic-arn'));
        const subscribeUrl = req.body.SubscribeURL;
        console.log('subscribeUrl' + subscribeUrl);
    }
});

我正在使用正文解析器作为中间件, 亚马逊在帖子请求中以文本\纯文本的形式发送内容类型,感谢这个论坛,直到我遇到这个问题,我才意识到类型 https://forums.aws.amazon.com/message.jspa? messageID = 261061#262098

I am using body parser as a middleware, amazon is sending content-type as text\plain in the post request thanks for this forum i did not realize the type until i cam accross this https://forums.aws.amazon.com/message.jspa?messageID=261061#262098

因此尝试了一些解决方法,以在使用bodyparser之前更改标头

so tried a work around to change the header before using the bodyparser

app.use(function(req, res, next) {
    if (req.get('x-amz-sns-message-type')) {
        req.headers['content-type'] = 'application/json';
    }
    next();
});
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: false }));

所以现在req被解析为json.

so now the req is parsed as json.

这篇关于aws sns确认订阅请求处理问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆