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

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

问题描述

我正在尝试为 s3 中的存储桶实现 aws sns 服务,我正在关注此文档 https://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.html据此,确认订阅请求中将有订阅 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.

推荐答案

我找到了我遗漏的东西,

I found what i was missing,

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);
    }
});

我使用正文解析器作为中间件,亚马逊在帖子请求中将内容类型发送为 textplain 感谢这个论坛我没有意识到类型,直到我穿过这个https://forums.aws.amazon.com/message.jspa?messageID=261061#262098

I am using body parser as a middleware, amazon is sending content-type as textplain 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天全站免登陆