cloudformation-helpers/aws/sns.js

33 lines
981 B
JavaScript
Raw Normal View History

var Promise = require('bluebird'),
AWS = require('aws-sdk'),
base = require('lib/base'),
helpers = require('lib/helpers'),
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
});
}
Subscribe.prototype.handleDelete = function(referenceData) {
if (referenceData) {
return sns.unsubscribeAsync({
SubscriptionArn: referenceData.SubscriptionArn
});
} else {
return helpers.futureSuccessful();
}
}
exports.subscribe = function(event, context) {
handler = new Subscribe(event, context, "SnsSubscribeFunction");
handler.handle();
}