diff --git a/src/index.js b/src/index.js index bc38a0d..e8aa1e5 100644 --- a/src/index.js +++ b/src/index.js @@ -53,7 +53,19 @@ module.exports = Class.extend({ FunctionName: { 'Fn::GetAtt': [ fnRef, 'Arn' ] }, Action: 'lambda:InvokeFunction', Principal: 'sns.amazonaws.com', - SourceArn: { 'Fn::Join': [ ':', [ 'arn:aws:sns', { 'Ref': 'AWS::Region' }, { 'Ref': 'AWS::AccountId' }, topicName ] ] }, + SourceArn: { + 'Fn::Join': [ + ':', + [ + 'arn', + { 'Ref': 'AWS::Partition' }, + 'sns', + { 'Ref': 'AWS::Region' }, + { 'Ref': 'AWS::AccountId' }, + topicName, + ], + ], + }, }, }; @@ -120,7 +132,7 @@ module.exports = Class.extend({ _getSubscriptionInfo: function(fnDef, topicName) { var self = this, - fnArn, acctID, region, topicArn, params; + fnArn, acctID, partition, region, topicArn, params; params = { FunctionName: fnDef.name }; @@ -129,9 +141,10 @@ module.exports = Class.extend({ fnArn = fn.Configuration.FunctionArn; // NOTE: assumes that the topic is in the same account and region at this // point + partition = fnArn.split(':')[1]; region = fnArn.split(':')[3]; acctID = fnArn.split(':')[4]; - topicArn = 'arn:aws:sns:' + region + ':' + acctID + ':' + topicName; + topicArn = 'arn:' + partition + ':sns:' + region + ':' + acctID + ':' + topicName; self._serverless.cli.log('Function ARN: ' + fnArn); self._serverless.cli.log('Topic ARN: ' + topicArn); diff --git a/src/tests/index.test.js b/src/tests/index.test.js index d679f1b..9dcd858 100644 --- a/src/tests/index.test.js +++ b/src/tests/index.test.js @@ -88,7 +88,19 @@ describe('serverless-plugin-external-sns-events', function() { FunctionName: { 'Fn::GetAtt': [ expFunctionName, 'Arn' ] }, Action: 'lambda:InvokeFunction', Principal: 'sns.amazonaws.com', - SourceArn: { 'Fn::Join': [ ':', [ 'arn:aws:sns', { 'Ref': 'AWS::Region' }, { 'Ref': 'AWS::AccountId' }, 'cool-Topic' ] ] }, + SourceArn: { + 'Fn::Join': [ + ':', + [ + 'arn', + { 'Ref': 'AWS::Partition' }, + 'sns', + { 'Ref': 'AWS::Region' }, + { 'Ref': 'AWS::AccountId' }, + 'cool-Topic', + ], + ], + }, }, };