Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(apigateway): authorizerUri does not resolve to the correct partition #8152

Merged
merged 2 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/authorizers/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class TokenAuthorizer extends LambdaAuthorizer {
name: props.authorizerName ?? this.node.uniqueId,
restApiId,
type: 'TOKEN',
authorizerUri: `arn:aws:apigateway:${Stack.of(this).region}:lambda:path/2015-03-31/functions/${props.handler.functionArn}/invocations`,
authorizerUri: lambdaAuthorizerArn(props.handler),
authorizerCredentials: props.assumeRole?.roleArn,
authorizerResultTtlInSeconds: props.resultsCacheTtl?.toSeconds(),
identitySource: props.identitySource || 'method.request.header.Authorization',
Expand Down Expand Up @@ -232,7 +232,7 @@ export class RequestAuthorizer extends LambdaAuthorizer {
name: props.authorizerName ?? this.node.uniqueId,
restApiId,
type: 'REQUEST',
authorizerUri: `arn:aws:apigateway:${Stack.of(this).region}:lambda:path/2015-03-31/functions/${props.handler.functionArn}/invocations`,
authorizerUri: lambdaAuthorizerArn(props.handler),
authorizerCredentials: props.assumeRole?.roleArn,
authorizerResultTtlInSeconds: props.resultsCacheTtl?.toSeconds(),
identitySource: props.identitySources.map(is => is.toString()).join(','),
Expand All @@ -248,3 +248,10 @@ export class RequestAuthorizer extends LambdaAuthorizer {
this.setupPermissions();
}
}

/**
* 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`;
}
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ export interface IntegrationProps {
* - If you specify HTTP for the `type` property, specify the API endpoint URL.
* - If you specify MOCK for the `type` property, don't specify this property.
* - If you specify AWS for the `type` property, specify an AWS service that
* follows this form: `arn:aws:apigateway:region:subdomain.service|service:path|action/service_api.`
* follows this form: `arn:partition:apigateway:region:subdomain.service|service:path|action/service_api.`
* For example, a Lambda function URI follows this form:
* arn:aws:apigateway:region:lambda:path/path. The path is usually in the
* arn:partition:apigateway:region:lambda:path/path. The path is usually in the
* form /2015-03-31/functions/LambdaFunctionARN/invocations.
*
* @see https://docs.aws.amazon.com/apigateway/api-reference/resource/integration/#uri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,30 +131,6 @@
"Name": "MyRestApi"
}
},
"MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyRestApi2D1F47A9"
},
"Description": "Automatically created by the RestApi construct"
},
"DependsOn": [
"MyRestApiANY05143F93"
]
},
"MyRestApiDeploymentStageprodC33B8E5F": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"RestApiId": {
"Ref": "MyRestApi2D1F47A9"
},
"DeploymentId": {
"Ref": "MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb"
},
"StageName": "prod"
}
},
"MyRestApiCloudWatchRoleD4042E8E": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down Expand Up @@ -200,6 +176,30 @@
"MyRestApi2D1F47A9"
]
},
"MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyRestApi2D1F47A9"
},
"Description": "Automatically created by the RestApi construct"
},
"DependsOn": [
"MyRestApiANY05143F93"
]
},
"MyRestApiDeploymentStageprodC33B8E5F": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"RestApiId": {
"Ref": "MyRestApi2D1F47A9"
},
"DeploymentId": {
"Ref": "MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb"
},
"StageName": "prod"
}
},
"MyRestApiANY05143F93": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
Expand Down Expand Up @@ -247,7 +247,11 @@
"Fn::Join": [
"",
[
"arn:aws:apigateway:",
"arn:",
{
"Ref": "AWS::Partition"
},
":apigateway:",
{
"Ref": "AWS::Region"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@
"Fn::Join": [
"",
[
"arn:aws:apigateway:",
"arn:",
{
"Ref": "AWS::Partition"
},
":apigateway:",
{
"Ref": "AWS::Region"
},
Expand Down Expand Up @@ -170,30 +174,6 @@
"Name": "MyRestApi"
}
},
"MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyRestApi2D1F47A9"
},
"Description": "Automatically created by the RestApi construct"
},
"DependsOn": [
"MyRestApiANY05143F93"
]
},
"MyRestApiDeploymentStageprodC33B8E5F": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"RestApiId": {
"Ref": "MyRestApi2D1F47A9"
},
"DeploymentId": {
"Ref": "MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb"
},
"StageName": "prod"
}
},
"MyRestApiCloudWatchRoleD4042E8E": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down Expand Up @@ -239,6 +219,30 @@
"MyRestApi2D1F47A9"
]
},
"MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyRestApi2D1F47A9"
},
"Description": "Automatically created by the RestApi construct"
},
"DependsOn": [
"MyRestApiANY05143F93"
]
},
"MyRestApiDeploymentStageprodC33B8E5F": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"RestApiId": {
"Ref": "MyRestApi2D1F47A9"
},
"DeploymentId": {
"Ref": "MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb"
},
"StageName": "prod"
}
},
"MyRestApiANY05143F93": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,30 +131,6 @@
"Name": "MyRestApi"
}
},
"MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyRestApi2D1F47A9"
},
"Description": "Automatically created by the RestApi construct"
},
"DependsOn": [
"MyRestApiANY05143F93"
]
},
"MyRestApiDeploymentStageprodC33B8E5F": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"RestApiId": {
"Ref": "MyRestApi2D1F47A9"
},
"DeploymentId": {
"Ref": "MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb"
},
"StageName": "prod"
}
},
"MyRestApiCloudWatchRoleD4042E8E": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down Expand Up @@ -200,6 +176,30 @@
"MyRestApi2D1F47A9"
]
},
"MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyRestApi2D1F47A9"
},
"Description": "Automatically created by the RestApi construct"
},
"DependsOn": [
"MyRestApiANY05143F93"
]
},
"MyRestApiDeploymentStageprodC33B8E5F": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"RestApiId": {
"Ref": "MyRestApi2D1F47A9"
},
"DeploymentId": {
"Ref": "MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb"
},
"StageName": "prod"
}
},
"MyRestApiANY05143F93": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
Expand Down Expand Up @@ -247,7 +247,11 @@
"Fn::Join": [
"",
[
"arn:aws:apigateway:",
"arn:",
{
"Ref": "AWS::Partition"
},
":apigateway:",
{
"Ref": "AWS::Region"
},
Expand Down
Loading