I am trying to subscribe my endpoint to an SNS https subscription. My code doesn't seem to be receiving SNS's POST request that sends the confirmation data. I am using Node with the express framework.
I have a feeling I'm not parsing the response correctly. I will attach my code.
Anyone see anything here that looks askew? Any help is appreciated.
var express = require('express');
var bodyParser = require('body-parser');
var router = express.Router();
var AWS = require('aws-sdk');
router.use(bodyParser.json());
router.use(bodyParser.urlencoded({ extended: false }));
AWS.config.update({
region: "us-east-1"
});
AWS.config.apiVersions = {
sns: '2010-03-31'
};
var sns = new AWS.SNS();
router.get('/', function(req, res) {
console.log('The GET is hitting');
res.send(req.body);
});
router.post('/', function(req, res) {
console.log('THE BODY IS ', req);
console.log('THE REQUEST BODY IS ', req.body);
if(req.body.Type === 'SubscriptionConfirmation') {
console.log("Subscription Confirmation Message--->"+req.body);
sns.confirmSubscription({
Token: req.body.Token,
TopicArn: req.body.TopicArn,
Type: req.body.Type
});
console.log('MESSAGE DATA IS ', req.body.Token);
} else if (req.body.Type === 'Notification') {
console.log('Notification has arrived')
} else {
console.log('Unexpected message ' + req.body)
}
});