Skip to content

Commit

Permalink
Fix SNS for case when function names where function name A startwith …
Browse files Browse the repository at this point in the history
…function name B

- test stack updated with case that covers the issue
  • Loading branch information
Sergii Kovalev authored and Aleksander Dikanski committed May 12, 2019
1 parent e12d157 commit c0a2079
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/stackops/apiGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
// Adjust permission to reference the function aliases
_.forOwn(apiLambdaPermissions, (permission, name) => {
const functionName = _.replace(name, /LambdaPermissionApiGateway$/, '');

const versionName = utils.getFunctionVersionName(versions, functionName);
const aliasName = utils.getAliasVersionName(aliases, functionName);
const isExternalRef = isExternalRefAuthorizerPredicate(permission.Properties.FunctionName);
Expand Down
15 changes: 15 additions & 0 deletions lib/stackops/snsEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
_.forOwn(lambdaSubscriptions, subscription => {
const functionNameRef = utils.findAllReferences(_.get(subscription, 'Endpoint'));
const functionName = _.replace(_.get(functionNameRef, '[0].ref', ''), /LambdaFunction$/, '');
<<<<<<< HEAD
const versionName = utils.getFunctionVersionName(versions, functionName);
const aliasName = utils.getAliasVersionName(aliases, functionName);
=======
const versionName = _.find(_.keys(versions), version => _.startsWith(version, `${functionName}LambdaVersion`));
const aliasName = _.find(_.keys(aliases), alias => _.startsWith(alias, `${functionName}Alias`));
>>>>>>> 6ac8882... Fix SNS for case when function names where function name A startwith function name B

subscription.Endpoint = { Ref: aliasName };

Expand All @@ -54,8 +59,13 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac

const functionNameRef = utils.findAllReferences(_.get(subscription.Properties, 'Endpoint'));
const functionName = _.replace(_.get(functionNameRef, '[0].ref', ''), /LambdaFunction$/, '');
<<<<<<< HEAD
const versionName = utils.getFunctionVersionName(versions, functionName);
const aliasName = utils.getAliasVersionName(aliases, functionName);
=======
const versionName = _.find(_.keys(versions), version => _.startsWith(version, `${functionName}LambdaVersion`));
const aliasName = _.find(_.keys(aliases), alias => _.startsWith(alias, `${functionName}Alias`));
>>>>>>> 6ac8882... Fix SNS for case when function names where function name A startwith function name B

subscription.Properties.Endpoint = { Ref: aliasName };
subscription.DependsOn = [ versionName, aliasName ];
Expand All @@ -72,8 +82,13 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
// Adjust permission to reference the function aliases
_.forOwn(snsLambdaPermissions, (permission, name) => {
const functionName = _.replace(name, /LambdaPermission.*$/, '');
<<<<<<< HEAD
const versionName = utils.getFunctionVersionName(versions, functionName);
const aliasName = utils.getAliasVersionName(aliases, functionName);
=======
const versionName = _.find(_.keys(versions), version => _.startsWith(version, `${functionName}LambdaVersion`));
const aliasName = _.find(_.keys(aliases), alias => _.startsWith(alias, `${functionName}Alias`));
>>>>>>> 6ac8882... Fix SNS for case when function names where function name A startwith function name B

// Adjust references and alias permissions
permission.Properties.FunctionName = { Ref: aliasName };
Expand Down

0 comments on commit c0a2079

Please sign in to comment.