Skip to content

(aws-cdk/api-gateway): No way to create a BasePathMapping that does not point to a stage #15806

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

Closed
Litee opened this issue Jul 28, 2021 · 5 comments · Fixed by #21488
Closed
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@Litee
Copy link
Contributor

Litee commented Jul 28, 2021

According to https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-basepathmapping.html it is possible to create mappings that do not point to any stage and point to REST API only. Current BasePathMapping construct does not allow this (see code snippet below).

Use Case

I have a production REST API that was created some time ago using CDK 1.45.0. In that version default base path mapping was created without stage specified, so all API users specify stage name as a part of the request URL. When upgrading to v1.115 I could not find a way to keep mapping the same using CDK, had to clone the construct into my project and patch it.

Proposed Solution

No good ideas. Maybe new static methods:

  • BasePathMapping.fromRestApi (same logic as the current constructor)
  • BasePathMapping.fromRestApiAndStage (allow to pass undefined value for stage into CFN) methods?

Other

/**
 * This resource creates a base path that clients who call your API must use in
 * the invocation URL.
 *
 * Unless you're importing a domain with `DomainName.fromDomainNameAttributes()`,
 * you can use `DomainName.addBasePathMapping()` to define mappings.
 */
export class BasePathMapping extends Resource {
  constructor(scope: Construct, id: string, props: BasePathMappingProps) {
    super(scope, id);

    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}`);
      }
    }

    // if restApi is an owned API and it has a deployment stage, map all requests
    // to that stage. otherwise, the stage will have to be specified in the URL.
    const stage = props.stage ?? (props.restApi instanceof RestApiBase
      ? props.restApi.deploymentStage
      : undefined);

    new CfnBasePathMapping(this, 'Resource', {
      basePath: props.basePath,
      domainName: props.domainName.domainName,
      restApiId: props.restApi.restApiId,
      stage: stage && stage.stageName,
    });
  }
}

This is a 🚀 Feature Request

@Litee Litee added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jul 28, 2021
@github-actions github-actions bot added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Jul 28, 2021
@gsdwait
Copy link

gsdwait commented Aug 3, 2021

We also ran into this issue. We're working around it by pulling the child CfnBasePathMapping and setting the stage to undefined.

@nija-at
Copy link
Contributor

nija-at commented Sep 1, 2021

The constructor for the BasePathMapping construct does not require the stage property.

Have you tried using that?

@nija-at nija-at added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Sep 1, 2021
@Litee
Copy link
Contributor Author

Litee commented Sep 13, 2021

Hi, Niranjan.

Unfortunately, if stage is not specified then BasePathMapping construct selects props.restApi.deploymentStage value - see constructor code I specified in my previous message. No way to propagate null/undefined into resulting CF template :(

Andrey Lipatkin.

@peterwoodworth peterwoodworth removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. needs-triage This issue or PR still needs to be triaged. labels Sep 20, 2021
@nija-at nija-at added effort/medium Medium work item – several days of effort p2 labels Oct 14, 2021
@nija-at
Copy link
Contributor

nija-at commented Oct 14, 2021

Thanks Andrey. Adding this to our backlog.

Unfortunately, we're unable to work on this right now. We use +1s and community feedback to evaluate its prioerity.
We accept PRs if you're interested in contributing.

@nija-at nija-at removed their assignment Nov 25, 2021
@mergify mergify bot closed this as completed in #21488 Oct 2, 2022
mergify bot pushed a commit that referenced this issue Oct 2, 2022
Closes #15806

Creates a new prop `attachToStage` to `BasePathMappingOptions` to allow a base path mapping to be created without a stage. Setting `stage` to `undefined` does not work, as in this case the default stage will be used.

----

### All Submissions:

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

### Adding new Unconventional Dependencies:

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

### New Features

* [x] 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
Contributor

github-actions bot commented Oct 2, 2022

⚠️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.

arewa pushed a commit to arewa/aws-cdk that referenced this issue Oct 8, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Closes aws#15806

Creates a new prop `attachToStage` to `BasePathMappingOptions` to allow a base path mapping to be created without a stage. Setting `stage` to `undefined` does not work, as in this case the default stage will be used.

----

### All Submissions:

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

### Adding new Unconventional Dependencies:

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

### New Features

* [x] 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*
homakk pushed a commit to homakk/aws-cdk that referenced this issue Dec 1, 2022

Verified

This commit was signed with the committer’s verified signature.
pflorek Patrick Florek
Closes aws#15806

Creates a new prop `attachToStage` to `BasePathMappingOptions` to allow a base path mapping to be created without a stage. Setting `stage` to `undefined` does not work, as in this case the default stage will be used.

----

### All Submissions:

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

### Adding new Unconventional Dependencies:

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

### New Features

* [x] 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 effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants