Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support govcloud and china regions #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
],
},
},
};

Expand Down Expand Up @@ -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 };

Expand All @@ -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);
Expand Down
14 changes: 13 additions & 1 deletion src/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
],
},
},
};

Expand Down