@@ -225,10 +225,14 @@ 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 isExternalRefAuthorizer = _ . every ( uriParts , part => ! _ . startsWith ( part , 'arn:aws:lambda' ) ) ;
229+ if ( isExternalRefAuthorizer ) {
230+ const funcIndex = _ . findIndex ( uriParts , part =>
231+ _ . has ( part , 'Fn::GetAtt' ) || _ . startsWith ( part , 'arn:aws:lambda' ) ) ;
229232
230- // Use the SERVERLESS_ALIAS stage variable to determine the called function alias
231- uriParts . splice ( funcIndex + 1 , 0 , ':${stageVariables.SERVERLESS_ALIAS}' ) ;
233+ // Use the SERVERLESS_ALIAS stage variable to determine the called function alias
234+ uriParts . splice ( funcIndex + 1 , 0 , ':${stageVariables.SERVERLESS_ALIAS}' ) ;
235+ }
232236 }
233237
234238 authorizer . Properties . Name = `${ authorizer . Properties . Name } -${ this . _alias } ` ;
@@ -265,9 +269,12 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
265269 const functionName = _ . replace ( name , / L a m b d a P e r m i s s i o n A p i G a t e w a y $ / , '' ) ;
266270 const versionName = _ . find ( _ . keys ( versions ) , version => _ . startsWith ( version , functionName ) ) ;
267271 const aliasName = _ . find ( _ . keys ( aliases ) , alias => _ . startsWith ( alias , functionName ) ) ;
272+ const isExternalRef = _ . startsWith ( permission . Properties . FunctionName , 'arn:aws:lambda' ) ;
268273
269274 // Adjust references and alias permissions
270- permission . Properties . FunctionName = { Ref : aliasName } ;
275+ if ( ! isExternalRef ) {
276+ permission . Properties . FunctionName = { Ref : aliasName } ;
277+ }
271278 if ( permission . Properties . SourceArn ) {
272279 // Authorizers do not set the SourceArn property
273280 permission . Properties . SourceArn = {
@@ -285,9 +292,13 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
285292 ]
286293 } ;
287294 }
288-
295+
289296 // Add dependency on function version
290- permission . DependsOn = [ versionName , aliasName ] ;
297+ if ( ! isExternalRef ) {
298+ permission . DependsOn = [ versionName , aliasName ] ;
299+ } else {
300+ permission . DependsOn = _ . compact ( [ versionName , aliasName ] ) ;
301+ }
291302
292303 delete stageStack . Resources [ name ] ;
293304 } ) ;
0 commit comments