2016-02-24 17:12:49 -05:00
|
|
|
var Promise = require('bluebird'),
|
|
|
|
AWS = require('aws-sdk'),
|
|
|
|
base = require('lib/base'),
|
|
|
|
sns = Promise.promisifyAll(new AWS.SNS());
|
|
|
|
|
|
|
|
// Exposes the SNS.subscribe API method
|
2016-03-04 10:02:41 -05:00
|
|
|
function Subscribe(event, context) {
|
|
|
|
base.Handler.call(this, event, context);
|
2016-02-24 17:12:49 -05:00
|
|
|
}
|
|
|
|
Subscribe.prototype = Object.create(base.Handler.prototype);
|
|
|
|
Subscribe.prototype.handleCreate = function() {
|
|
|
|
var p = this.event.ResourceProperties;
|
|
|
|
return sns.subscribeAsync({
|
|
|
|
Endpoint: p.Endpoint,
|
|
|
|
Protocol: p.Protocol,
|
|
|
|
TopicArn: p.TopicArn
|
2016-02-24 22:13:48 -05:00
|
|
|
});
|
2016-02-24 17:12:49 -05:00
|
|
|
}
|
|
|
|
Subscribe.prototype.handleDelete = function(referenceData) {
|
2016-03-04 12:02:15 -05:00
|
|
|
return Promise.try(function() {
|
|
|
|
if (referenceData && referenceData.SubscriptionArn) {
|
|
|
|
return sns.unsubscribeAsync({
|
|
|
|
SubscriptionArn: referenceData.SubscriptionArn
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2016-02-24 17:12:49 -05:00
|
|
|
}
|
|
|
|
exports.subscribe = function(event, context) {
|
2016-03-04 10:02:41 -05:00
|
|
|
handler = new Subscribe(event, context);
|
2016-02-24 17:12:49 -05:00
|
|
|
handler.handle();
|
|
|
|
}
|