Shivaraj Nesargi
Shivaraj Nesargi

Reputation: 139

Unable to confirm aws Sns subscription for a http endpoint in NodeJS

I have used the following piece of code to handle the AWS SNS subscription and notification messages. The configured http endpoint is receiving the confirmation message but I am unable to confirm it through code. However the manual confirmation of it is happening by visiting the "subscription url" from the logged console message.

I have configured the aws and sns part as mentioned below:

var aws = require('aws-sdk');
aws.config.loadFromPath(__dirname + '/awsConfig.json');
var sns = new aws.SNS();

This is the following function I am using for handling http endpoint messages.

function handleIncomingMessage(msgType, msgData) {
    if (msgType === 'SubscriptionConfirmation') {
        //confirm the subscription.
        console.log("Subscription Confirmation Message--->"+msgData);
        sns.confirmSubscription({
            TopicArn: msgData.TopicArn
        }, onAwsResponse);
    } else if (msgType === 'Notification') {
        console.log("Notification has arrived");
    } else {
        console.log('Unexpected message type ' + msgType);
    }
}

Here the sns.confirmSubscription isn't working, Is there any solution/work around for this?

Upvotes: 3

Views: 1039

Answers (1)

alexoakley1
alexoakley1

Reputation: 565

You also need to pass a Token field in the confirmSubscription parameters as described here.

Upvotes: 1

Related Questions