How to publish sns to a specific endpoint?

Alex Cebotari picture Alex Cebotari · Oct 14, 2013 · Viewed 25.3k times · Source

I have a issue with publishing sns to a specific endpoint.

My code:

var AWS = require('aws-sdk');
AWS.config.loadFromPath('/web/config.json');

var sns = new AWS.SNS();
sns.publish({
    // TopicArn:'arn:aws:sns:us-west-2:302467918846:MyTestTopik',
    TargetArn: 'arn:aws:sns:us-west-2:302467918846:MyTestTopik:613ee49c-d4dc-4354-a7e6-c1d9d8277c56',
    Message: "Success!!! ",
    Subject: "TestSNS"
}, function(err, data) {
    if (err) {
        console.log("Error sending a message " + err);
    } else {
        console.log("Sent message: " + data.MessageId);

    }
});

When I use TopicArn, everything is fine. But when I try to send notification to a specific endpoint I take error:

Error sending a message InvalidParameter: Invalid parameter: Topic Name

And I have no idea what kind of parameters it is and from where.

Answer

guya picture guya · Oct 19, 2013

Something similar is working fine for me. I'm able to publish to a specific endpoint using: Apple Push Notification Service Sandbox (APNS_SANDBOX)

You might also want to try and update the aws-sdk, current version is 1.9.0.

Here's my code, TargetArn was copied directly from the SNS console. I omitted some of the data, like &

var sns = new AWS.SNS();
var params = {
    TargetArn:'arn:aws:sns:us-west-2:302467918846:endpoint/APNS_SANDBOX/<APP_NAME>/<USER_TOKEN>'
    Message:'Success!!! ',
    Subject: 'TestSNS'
};

sns.publish(params, function(err,data){
        if (err) {
            console.log('Error sending a message', err);
        } else {
            console.log('Sent message:', data.MessageId);
        }
    });