2016-02-24 17:12:49 -05:00
|
|
|
var Promise = require('bluebird'),
|
|
|
|
AWS = require('aws-sdk'),
|
|
|
|
base = require('lib/base'),
|
2016-02-26 10:28:25 -05:00
|
|
|
helpers = require('lib/helpers'),
|
2016-02-24 17:12:49 -05:00
|
|
|
sns = Promise.promisifyAll(new AWS.SNS());
|
|
|
|
|
|
|
|
// Exposes the SNS.subscribe API method
|
|
|
|
function Subscribe(event, context, functionIdentifier) {
|
|
|
|
base.Handler.call(this, event, context, functionIdentifier);
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
if (referenceData) {
|
|
|
|
return sns.unsubscribeAsync({
|
|
|
|
SubscriptionArn: referenceData.SubscriptionArn
|
|
|
|
});
|
|
|
|
} else {
|
2016-02-26 10:28:25 -05:00
|
|
|
return helpers.futureSuccessful();
|
2016-02-24 17:12:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.subscribe = function(event, context) {
|
|
|
|
handler = new Subscribe(event, context, "SnsSubscribeFunction");
|
|
|
|
handler.handle();
|
|
|
|
}
|