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

aws_apigateway: unable to add multi-level base path mappings #23347

Closed
VarunWachaspati opened this issue Dec 14, 2022 · 2 comments · Fixed by #23362
Closed

aws_apigateway: unable to add multi-level base path mappings #23347

VarunWachaspati opened this issue Dec 14, 2022 · 2 comments · Fixed by #23362
Assignees
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@VarunWachaspati
Copy link
Contributor

Describe the bug

As per this AWS announcement post, API Gateway support multi-level path mappings like api/v2/action or api/example-api now.

Now when I try to add a base path mapping containing a slash(/) via CDK it throws an error even though the same can be achieved via the AWS console successfully.

Expected Behavior

Should be able to add multi-level base path mappings containing slashes(/) via CDK.

Current Behavior

Throws the following error when you try to add multi-level base path mapping in API Gateway -

Error: A base path may only contain letters, numbers, and one of "$-_.+!*'()", received: api/example-api
at new BasePathMapping (/tmp/artifact/node_modules/aws-cdk-lib/aws-apigateway/lib/base-path-mapping.js:1:759)

Reproduction Steps

Sample CDK code to reproduce the issue -

const domainName = apigateway.DomainName.fromDomainNameAttributes(this, 'DomainName', {
  domainName: 'domainName',
  domainNameAliasHostedZoneId: 'domainNameAliasHostedZoneId',
  domainNameAliasTarget: 'domainNameAliasTarget',
});

new apigateway.BasePathMapping(this, 'BasePathMapping', {
  domainName: domainName,
  restApi: api,
  basePath: 'api/example-api',
});

Possible Solution

Modify the following validation to accommodate slash(/) -

if (props.basePath && !Token.isUnresolved(props.basePath)) {
if (!props.basePath.match(/^[a-zA-Z0-9$_.+!*'()-]+$/)) {
throw new Error(`A base path may only contain letters, numbers, and one of "$-_.+!*'()", received: ${props.basePath}`);
}
}

I can contribute to fix this issue if the above proposed solution is acceptable.

Additional Information/Context

No response

CDK CLI Version

2.46.0

Framework Version

No response

Node.js Version

14.17.1

OS

MacOS Monterey 12.5

Language

Typescript

Language Version

No response

Other information

No response

@VarunWachaspati VarunWachaspati added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 14, 2022
@github-actions github-actions bot added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Dec 14, 2022
@VarunWachaspati
Copy link
Contributor Author

Also, if possible can anyone suggest a work around for this issue in the meanwhile. Would greatly appreciate it.

@mergify mergify bot closed this as completed in #23362 Dec 17, 2022
mergify bot pushed a commit that referenced this issue Dec 17, 2022
API Gateway allows multi-level base path mapping but CDK doesn't support the same yet. ([AWS Announcement Post](https://aws.amazon.com/about-aws/whats-new/2021/03/amazon-api-gateway-custom-domain-names-support-multi-level-base-path-mappings/))
Also, added new base path mapping validations such as shouldn't start or end with `/` or shouldn't contain consecutive `/`. 

fixes #23347 
----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Construct Runtime Dependencies:

* [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

brennanho pushed a commit to brennanho/aws-cdk that referenced this issue Jan 20, 2023
API Gateway allows multi-level base path mapping but CDK doesn't support the same yet. ([AWS Announcement Post](https://aws.amazon.com/about-aws/whats-new/2021/03/amazon-api-gateway-custom-domain-names-support-multi-level-base-path-mappings/))
Also, added new base path mapping validations such as shouldn't start or end with `/` or shouldn't contain consecutive `/`. 

fixes aws#23347 
----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Construct Runtime Dependencies:

* [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
brennanho pushed a commit to brennanho/aws-cdk that referenced this issue Feb 22, 2023
API Gateway allows multi-level base path mapping but CDK doesn't support the same yet. ([AWS Announcement Post](https://aws.amazon.com/about-aws/whats-new/2021/03/amazon-api-gateway-custom-domain-names-support-multi-level-base-path-mappings/))
Also, added new base path mapping validations such as shouldn't start or end with `/` or shouldn't contain consecutive `/`. 

fixes aws#23347 
----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Construct Runtime Dependencies:

* [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants