@@ -225,10 +225,14 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
225
225
const authorizerType = _ . get ( authorizer , 'Properties.Type' ) ;
226
226
if ( authorizerType === 'TOKEN' || authorizerType === 'REQUEST' ) {
227
227
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' ) ) ;
229
232
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
+ }
232
236
}
233
237
234
238
authorizer . Properties . Name = `${ authorizer . Properties . Name } -${ this . _alias } ` ;
@@ -265,9 +269,12 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
265
269
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 $ / , '' ) ;
266
270
const versionName = _ . find ( _ . keys ( versions ) , version => _ . startsWith ( version , functionName ) ) ;
267
271
const aliasName = _ . find ( _ . keys ( aliases ) , alias => _ . startsWith ( alias , functionName ) ) ;
272
+ const isExternalRef = _ . startsWith ( permission . Properties . FunctionName , 'arn:aws:lambda' ) ;
268
273
269
274
// Adjust references and alias permissions
270
- permission . Properties . FunctionName = { Ref : aliasName } ;
275
+ if ( ! isExternalRef ) {
276
+ permission . Properties . FunctionName = { Ref : aliasName } ;
277
+ }
271
278
if ( permission . Properties . SourceArn ) {
272
279
// Authorizers do not set the SourceArn property
273
280
permission . Properties . SourceArn = {
@@ -285,9 +292,13 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
285
292
]
286
293
} ;
287
294
}
288
-
295
+
289
296
// 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
+ }
291
302
292
303
delete stageStack . Resources [ name ] ;
293
304
} ) ;
0 commit comments