Skip to content

Commit f502a95

Browse files
author
Aleksander Dikanski
committed
Add support for referenced custom authorizer lambdas
1 parent 89de546 commit f502a95

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/stackops/apiGateway.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
225225
const authorizerType = _.get(authorizer, 'Properties.Type');
226226
if (authorizerType === 'TOKEN' || authorizerType === 'REQUEST') {
227227
const uriParts = authorizer.Properties.AuthorizerUri['Fn::Join'][1];
228-
const funcIndex = _.findIndex(uriParts, part => _.has(part, 'Fn::GetAtt'));
228+
const funcIndex = _.findIndex(uriParts, part =>
229+
_.has(part, 'Fn::GetAtt') || (part.startsWith && part.startsWith('arn:aws:lambda')));
229230

230231
// Use the SERVERLESS_ALIAS stage variable to determine the called function alias
231232
uriParts.splice(funcIndex + 1, 0, ':${stageVariables.SERVERLESS_ALIAS}');
@@ -267,7 +268,7 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
267268
const aliasName = _.find(_.keys(aliases), alias => _.startsWith(alias, functionName));
268269

269270
// Adjust references and alias permissions
270-
permission.Properties.FunctionName = { Ref: aliasName };
271+
permission.Properties.FunctionName = aliasName ? { Ref: aliasName } : permission.Properties.FunctionName;
271272
if (permission.Properties.SourceArn) {
272273
// Authorizers do not set the SourceArn property
273274
permission.Properties.SourceArn = {
@@ -287,7 +288,7 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
287288
}
288289

289290
// Add dependency on function version
290-
permission.DependsOn = [ versionName, aliasName ];
291+
permission.DependsOn = [ versionName, aliasName ].filter(name => name);
291292

292293
delete stageStack.Resources[name];
293294
});

0 commit comments

Comments
 (0)