Reputation: 1304
I am trying to implement push notification using Amazon SNS in Node. I have created a topic and published a message using below code
Create Topic
var createTopicPromise = new AWS.SNS({apiVersion: '2010-03-31'}).createTopic({Name: "TOPIC_NAME"}).promise();
// Handle promise's fulfilled/rejected states
createTopicPromise.then(
function(data) {
console.log("Topic ARN is " + data.TopicArn);
}).catch(
function(err) {
console.error(err, err.stack);
});
I got a TopicArn
something like this arn:aws:sns:us-east-1:xxxxxxxxxx:TOPIC_NAME
Publish
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set region
AWS.config.update({region: 'REGION'});
// Create publish parameters
var params = {
Message: 'You Got Message!! Hello....', /* required */
TopicArn: 'arn:aws:sns:us-east-1:xxxxxxxxxx:TOPIC_NAME'
};
// Create promise and SNS service object
var publishTextPromise = new AWS.SNS({apiVersion: '2010-03-31'}).publish(params).promise();
// Handle promise's fulfilled/rejected states
publishTextPromise.then(
function(data) {
console.log("Message ${params.Message} send sent to the topic ${params.TopicArn}");
console.log("MessageID is " + data.MessageId);
}).catch(
function(err) {
console.error(err, err.stack);
});
Now the message have been published now I need to see this on my mobile. So I used subscribe code like this
var params = {
Protocol: 'application', /* required */
TopicArn: 'arn:aws:sns:us-east-1:xxxxxxxxxx:TOPIC_NAME', /* required */
Endpoint: 'MOBILE_ENDPOINT_ARN'
};
// Create promise and SNS service object
var subscribePromise = new AWS.SNS({ apiVersion: '2010-03-31' }).subscribe(params).promise();
req;
res;
// Handle promise's fulfilled/rejected states
subscribePromise.then(
function (data) {
console.log("Subscription ARN is " + data.SubscriptionArn);
}).catch(
function (err) {
console.error(err, err.stack);
});
}
My question is what is Endpoint
in Subscribe params. Where should I get this? and So far Am I right ? Please help me out.
Upvotes: 2
Views: 1460
Reputation: 68715
Endpoint here is the ARN of your mobile application that you need to register with AWS. Here is the snippet from the official documentation
For Amazon SNS to send notification messages to mobile endpoints, whether it is direct or with subscriptions to a topic, you first need to register the app with AWS.
Source : https://docs.aws.amazon.com/sns/latest/dg/mobile-push-send-register.html
Upvotes: 1