Skip to content

Commit

Permalink
fix(aws-apigateway): cross region authorizer ref (aws#18444)
Browse files Browse the repository at this point in the history
Fixes: aws#18443

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
shooit authored and TikiTDO committed Feb 21, 2022
1 parent 2c77a94 commit e619dd3
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 20 deletions.
5 changes: 3 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/authorizers/lambda.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as iam from '@aws-cdk/aws-iam';
import * as lambda from '@aws-cdk/aws-lambda';
import { Duration, Lazy, Names, Stack } from '@aws-cdk/core';
import { Arn, ArnFormat, Duration, Lazy, Names, Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnAuthorizer } from '../apigateway.generated';
import { Authorizer, IAuthorizer } from '../authorizer';
Expand Down Expand Up @@ -254,5 +254,6 @@ export class RequestAuthorizer extends LambdaAuthorizer {
* constructs the authorizerURIArn.
*/
function lambdaAuthorizerArn(handler: lambda.IFunction) {
return `arn:${Stack.of(handler).partition}:apigateway:${Stack.of(handler).region}:lambda:path/2015-03-31/functions/${handler.functionArn}/invocations`;
const { region, partition } = Arn.split( handler.functionArn, ArnFormat.COLON_RESOURCE_NAME);
return `arn:${partition}:apigateway:${region}:lambda:path/2015-03-31/functions/${handler.functionArn}/invocations`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,37 @@
[
"arn:",
{
"Ref": "AWS::Partition"
"Fn::Select": [
1,
{
"Fn::Split": [
":",
{
"Fn::GetAtt": [
"MyAuthorizerFunction70F1223E",
"Arn"
]
}
]
}
]
},
":apigateway:",
{
"Ref": "AWS::Region"
"Fn::Select": [
3,
{
"Fn::Split": [
":",
{
"Fn::GetAtt": [
"MyAuthorizerFunction70F1223E",
"Arn"
]
}
]
}
]
},
":lambda:path/2015-03-31/functions/",
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,37 @@
[
"arn:",
{
"Ref": "AWS::Partition"
"Fn::Select": [
1,
{
"Fn::Split": [
":",
{
"Fn::GetAtt": [
"MyAuthorizerFunction70F1223E",
"Arn"
]
}
]
}
]
},
":apigateway:",
{
"Ref": "AWS::Region"
"Fn::Select": [
3,
{
"Fn::Split": [
":",
{
"Fn::GetAtt": [
"MyAuthorizerFunction70F1223E",
"Arn"
]
}
]
}
]
},
":lambda:path/2015-03-31/functions/",
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,37 @@
[
"arn:",
{
"Ref": "AWS::Partition"
"Fn::Select": [
1,
{
"Fn::Split": [
":",
{
"Fn::GetAtt": [
"MyAuthorizerFunction70F1223E",
"Arn"
]
}
]
}
]
},
":apigateway:",
{
"Ref": "AWS::Region"
"Fn::Select": [
3,
{
"Fn::Split": [
":",
{
"Fn::GetAtt": [
"MyAuthorizerFunction70F1223E",
"Arn"
]
}
]
}
]
},
":lambda:path/2015-03-31/functions/",
{
Expand Down
144 changes: 132 additions & 12 deletions packages/@aws-cdk/aws-apigateway/test/authorizers/lambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,31 @@ describe('lambda authorizer', () => {
[
'arn:',
{
Ref: 'AWS::Partition',
'Fn::Select': [
1,
{
'Fn::Split': [
':',
{
'Fn::GetAtt': ['myfunction9B95E948', 'Arn'],
},
],
},
],
},
':apigateway:',
{
Ref: 'AWS::Region',
'Fn::Select': [
3,
{
'Fn::Split': [
':',
{
'Fn::GetAtt': ['myfunction9B95E948', 'Arn'],
},
],
},
],
},
':lambda:path/2015-03-31/functions/',
{
Expand Down Expand Up @@ -89,11 +109,31 @@ describe('lambda authorizer', () => {
[
'arn:',
{
Ref: 'AWS::Partition',
'Fn::Select': [
1,
{
'Fn::Split': [
':',
{
'Fn::GetAtt': ['myfunction9B95E948', 'Arn'],
},
],
},
],
},
':apigateway:',
{
Ref: 'AWS::Region',
'Fn::Select': [
3,
{
'Fn::Split': [
':',
{
'Fn::GetAtt': ['myfunction9B95E948', 'Arn'],
},
],
},
],
},
':lambda:path/2015-03-31/functions/',
{
Expand Down Expand Up @@ -167,11 +207,31 @@ describe('lambda authorizer', () => {
[
'arn:',
{
Ref: 'AWS::Partition',
'Fn::Select': [
1,
{
'Fn::Split': [
':',
{
'Fn::GetAtt': ['myfunction9B95E948', 'Arn'],
},
],
},
],
},
':apigateway:',
{
Ref: 'AWS::Region',
'Fn::Select': [
3,
{
'Fn::Split': [
':',
{
'Fn::GetAtt': ['myfunction9B95E948', 'Arn'],
},
],
},
],
},
':lambda:path/2015-03-31/functions/',
{
Expand Down Expand Up @@ -218,11 +278,31 @@ describe('lambda authorizer', () => {
[
'arn:',
{
Ref: 'AWS::Partition',
'Fn::Select': [
1,
{
'Fn::Split': [
':',
{
'Fn::GetAtt': ['myfunction9B95E948', 'Arn'],
},
],
},
],
},
':apigateway:',
{
Ref: 'AWS::Region',
'Fn::Select': [
3,
{
'Fn::Split': [
':',
{
'Fn::GetAtt': ['myfunction9B95E948', 'Arn'],
},
],
},
],
},
':lambda:path/2015-03-31/functions/',
{
Expand Down Expand Up @@ -269,11 +349,31 @@ describe('lambda authorizer', () => {
[
'arn:',
{
Ref: 'AWS::Partition',
'Fn::Select': [
1,
{
'Fn::Split': [
':',
{
'Fn::GetAtt': ['myfunction9B95E948', 'Arn'],
},
],
},
],
},
':apigateway:',
{
Ref: 'AWS::Region',
'Fn::Select': [
3,
{
'Fn::Split': [
':',
{
'Fn::GetAtt': ['myfunction9B95E948', 'Arn'],
},
],
},
],
},
':lambda:path/2015-03-31/functions/',
{
Expand Down Expand Up @@ -341,11 +441,31 @@ describe('lambda authorizer', () => {
[
'arn:',
{
Ref: 'AWS::Partition',
'Fn::Select': [
1,
{
'Fn::Split': [
':',
{
'Fn::GetAtt': ['myfunction9B95E948', 'Arn'],
},
],
},
],
},
':apigateway:',
{
Ref: 'AWS::Region',
'Fn::Select': [
3,
{
'Fn::Split': [
':',
{
'Fn::GetAtt': ['myfunction9B95E948', 'Arn'],
},
],
},
],
},
':lambda:path/2015-03-31/functions/',
{
Expand Down

0 comments on commit e619dd3

Please sign in to comment.