mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Merge pull request #962 from martinbooth/sns_allow_topic_arn
Allow topicArn config for sns event instead of topicName
This commit is contained in:
commit
4ce93cd73a
@ -49,8 +49,10 @@ module.exports = function(S) {
|
||||
functionName = event.getFunction().getDeployedName(_this.evt.options),
|
||||
statementId = 'sEvents-' + functionName + '-' + event.name + '-' + _this.evt.options.stage,
|
||||
awsAccountId = _this.aws.getAccountId(_this.evt.options.stage, _this.evt.options.region),
|
||||
topicArn = 'arn:aws:sns:' + _this.evt.options.region + ':' + awsAccountId + ':' + populatedEvent.config.topicName,
|
||||
lambdaArn = 'arn:aws:lambda:' + _this.evt.options.region + ':' + awsAccountId + ':function:' + functionName + ':' + _this.evt.options.stage;
|
||||
lambdaArn = 'arn:aws:lambda:' + _this.evt.options.region + ':' + awsAccountId + ':function:' + functionName + ':' + _this.evt.options.stage,
|
||||
topic = populatedEvent.config.topic || populatedEvent.config.topicName,
|
||||
topicArn = topic && topic.indexOf('arn:') === 0 ? topic : ('arn:aws:sns:' + _this.evt.options.region + ':' + awsAccountId + ':' + topic),
|
||||
topicRegion = /arn:aws:sns:(.*):(.*):(.*)/.exec(topicArn)[1];
|
||||
|
||||
let params = {
|
||||
FunctionName: lambdaArn,
|
||||
@ -81,7 +83,7 @@ module.exports = function(S) {
|
||||
TopicArn: topicArn,
|
||||
Endpoint: lambdaArn
|
||||
};
|
||||
return _this.aws.request('SNS', 'subscribe', params, _this.evt.options.stage, _this.evt.options.region)
|
||||
return _this.aws.request('SNS', 'subscribe', params, _this.evt.options.stage, topicRegion)
|
||||
})
|
||||
.then(function(data){
|
||||
SUtils.sDebug(`Subscription to SNS topic ${topicArn} added for lambda ${lambdaArn}`);
|
||||
|
||||
@ -276,13 +276,15 @@ class EventRemover extends S.classes.Plugin {
|
||||
awsAccountId = this.aws.getAccountId(stage, region),
|
||||
Endpoint = 'arn:aws:lambda:' + region + ':' + awsAccountId + ':function:' + functionName + ':' + stage,
|
||||
populatedEvent = event.toObjectPopulated({stage, region}),
|
||||
TopicArn = 'arn:aws:sns:' + region + ':' + awsAccountId + ':' + populatedEvent.config.topicName;
|
||||
topic = populatedEvent.config.topic || populatedEvent.config.topicName,
|
||||
TopicArn = topic && topic.indexOf('arn:') === 0 ? topic : ('arn:aws:sns:' + region + ':' + awsAccountId + ':' + topic),
|
||||
TopicRegion = /arn:aws:sns:(.*):(.*):(.*)/.exec(TopicArn)[1];
|
||||
|
||||
return this._SNSlistSubscriptionsByTopic(TopicArn, stage, region)
|
||||
return this._SNSlistSubscriptionsByTopic(TopicArn, stage, TopicRegion)
|
||||
.then((subscriptions) => _.filter(subscriptions, {Endpoint}))
|
||||
.then((subscriptions) => subscriptions.length && subscriptions || BbPromise.reject(new SError(`Subscription for "${event.name}" is not found`)))
|
||||
.map((subscription) => subscription.SubscriptionArn)
|
||||
.map((SubscriptionArn) => this.aws.request('SNS', 'unsubscribe', {SubscriptionArn}, stage, region));
|
||||
.map((SubscriptionArn) => this.aws.request('SNS', 'unsubscribe', {SubscriptionArn}, stage, TopicRegion));
|
||||
}
|
||||
|
||||
_SNSlistSubscriptionsByTopic(TopicArn, stage, region, NextToken, subscriptions) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user