amazon-web-servicesamazon-sns

setting up my first SNS node end point, the confirmation always is an empty


I am using node.js as my endpoint for SNS (this is my first one , correct aws terms may be missing)

The node code is pretty simple

I am using express and in my route i have

router.post('/bounce', 
     bodyParser.urlencoded({extended: true}),
     bodyParser.json(), function (req, res, next) {

  console.log("Recieving a new post ");
  console.log(req.body);
  res.setHeader('Content-Type', 'application/json');
  res.send(JSON.stringify({success: true}));

});

When i subscribe via the SNS console i see the incoming post but it is always an empty object. To verify the endpoint is working i post from postman with a json object and it displays what i would expect

I have the node amazon sdk , but I do not understand where that fits in the picture

I assume i must be missing a step??

thanks for any help


Solution

  • This is what i had to do to get what i needed

    var express = require('express');
    var bodyParser = require('body-parser');
    var http = require('http');
    var router = express.Router();
    
    var app = express();
    
    app.use(bodyParser.json());
    app.use(router);
    
    router.post('/bounce', function(req, res){
    
        var chunks = [];
        req.on('data', function (chunk) {
            chunks.push(chunk);
        });
        req.on('end', function () {
            var message = JSON.parse(chunks.join(''));
            console.log(message);
        });
        res.end();
    
    });
    
    http.createServer( app).listen(4040, function () {
       console.log("server listening on port " + 4040);
    });