-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunsubscribe.js
34 lines (32 loc) · 1.03 KB
/
unsubscribe.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var AWS = require("aws-sdk");
console.log('Loading function');
exports.handler = (event, context, callback) => {
var sns = new AWS.SNS();
var inputNumber = (event.query.number === undefined ? "" : event.query.number);
var params = {
TopicArn: 'your-topic-arn', /* enter your arn */
//NextToken: 'moreSubs'
};
var removeARN = "";
sns.listSubscriptionsByTopic(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else{
for (var i = 0; i<data.Subscriptions.length;i++){
if (data.Subscriptions[i].Endpoint == '+' + inputNumber){
removeARN = data.Subscriptions[i].SubscriptionArn;
unsubscribeSMS(removeARN);
break;
}
}
}
});
function unsubscribeSMS(arn){
var unsubParams = {
SubscriptionArn: arn
};
sns.unsubscribe(unsubParams, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
}
};