From 84183783db263f9605ef015ecea40b30c767c5c5 Mon Sep 17 00:00:00 2001 From: Aleksander Dikanski Date: Fri, 16 Mar 2018 20:44:32 +0100 Subject: [PATCH] Fix issue wit custom authorizers when using pseudo parameters plugin --- lib/stackops/apiGateway.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/stackops/apiGateway.js b/lib/stackops/apiGateway.js index fdbca2f..9ca6e1e 100644 --- a/lib/stackops/apiGateway.js +++ b/lib/stackops/apiGateway.js @@ -221,17 +221,16 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac }); // Audjust authorizer Uri and name (stage variables are not allowed in Uris here) + const isExternalRefAuthorizerPredicate = part => _.startsWith(part, 'arn:aws:lambda') || + (_.has(part, 'Fn::Sub') && _.startsWith(part['Fn::Sub'], 'arn:aws:lambda')); _.forOwn(authorizers, (authorizer, name) => { const authorizerType = _.get(authorizer, 'Properties.Type'); if (authorizerType === 'TOKEN' || authorizerType === 'REQUEST') { const uriParts = authorizer.Properties.AuthorizerUri['Fn::Join'][1]; - const isExternalRefAuthorizer = _.every(uriParts, part => !_.startsWith(part, 'arn:aws:lambda')); - if (isExternalRefAuthorizer) { - const funcIndex = _.findIndex(uriParts, part => - _.has(part, 'Fn::GetAtt') || _.startsWith(part, 'arn:aws:lambda')); - - // Use the SERVERLESS_ALIAS stage variable to determine the called function alias - uriParts.splice(funcIndex + 1, 0, ':${stageVariables.SERVERLESS_ALIAS}'); + const isExternalRefAuthorizer = _.some(uriParts, isExternalRefAuthorizerPredicate); + if (!isExternalRefAuthorizer) { + const funcIndex = _.findIndex(uriParts, part => _.startsWith(part, '/invocations')); + uriParts.splice(funcIndex , 0, ':${stageVariables.SERVERLESS_ALIAS}'); } } @@ -269,7 +268,7 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac const functionName = _.replace(name, /LambdaPermissionApiGateway$/, ''); const versionName = _.find(_.keys(versions), version => _.startsWith(version, functionName)); const aliasName = _.find(_.keys(aliases), alias => _.startsWith(alias, functionName)); - const isExternalRef = _.startsWith(permission.Properties.FunctionName, 'arn:aws:lambda'); + const isExternalRef = isExternalRefAuthorizerPredicate(permission.Properties.FunctionName); // Adjust references and alias permissions if (!isExternalRef) {