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

feat(apigateway): support multi-level paths for custom domains #22463

Merged
merged 4 commits into from
Oct 19, 2022
Merged

feat(apigateway): support multi-level paths for custom domains #22463

merged 4 commits into from
Oct 19, 2022

Conversation

corymhall
Copy link
Contributor

This PR adds support for multi-level paths in api mappings for custom domains. This is a unique case because in order to create multi-level mappings for RestApis (ApiGateway v1) you have to use the ApiGateway v2 API.

The aws-apigatewayv2 package is currently an alpha module so this cannot depend on that module which is why I used the L1 level to implement this support.

I thought about deprecating the v1 api (BasePathMapping), but that is still a valid API (and is required if you have an EDGE domain name). The experience I landed on was to mostly make it transparent to users. When users create a DomainName, it will now create either a BasePathMapping or an ApiMapping depending on whether they provide a multi-level basePath. I did have to introduce a new addApiMapping method since addBasePathMapping has a return type of BasePathMapping.

I also removed the validation that prevented users from adding additional basePaths if a (none) basePath was already created. It seems like that limitation was removed at some point and I have added an integration test to confirm.

fixes #15904


All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • 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

This PR adds support for multi-level paths in api mappings for custom
domains. This is a unique case because in order to create multi-level
mappings for RestApis (ApiGateway v1) you have to use the ApiGateway v2 API.

The aws-apigatewayv2 package is currently an alpha module so this cannot
depend on that module which is why I used the L1 level to implement this
support.

I thought about deprecating the v1 api (BasePathMapping), but that is
still a valid API (and is required if you have an EDGE domain name). The
experience I landed on was to mostly make it transparent to users. When
users create a DomainName, it will now create either a BasePathMapping
or an ApiMapping depending on whether they provide a multi-level
basePath. I did have to introduce a new `addApiMapping` method since
`addBasePathMapping` has a return type of `BasePathMapping`.

I also removed the validation that prevented users from adding
additional basePaths if a (none) basePath was already created. It seems
like that limitation was removed at some point and I have added an
integration test to confirm.

fixes #15904
@gitpod-io
Copy link

gitpod-io bot commented Oct 11, 2022

@aws-cdk-automation aws-cdk-automation requested a review from a team October 11, 2022 19:46
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1 labels Oct 11, 2022
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Oct 11, 2022
@@ -132,6 +135,11 @@
"lib/apigatewayv2.js"
]
},
"pkglint": {
"exclude": [
"no-experimental-dependencies"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to depend on the apigatewayv2 L1s. This doesn't cause aws-apigateway to depend on aws-apigatewayv2-alpha, it's just makes you fail faster if you add a dependency to an experimental V2. ubergen will strip out the L2s from aws-apigatewayv2.

@Naumel Naumel added the pr/do-not-merge This PR should not be merged at this time. label Oct 12, 2022
Copy link
Contributor

@Naumel Naumel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 I have a number of nitpicks, and a couple of comments related to validations.

Nothing that could not be followed-up on in a short PR after merging, but adding the label in case we should have a chat when everyone is online.

*
* @default - map requests from the domain root (e.g. `example.com`).
*/
readonly basePath?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Should this be more restrictive and having another name?

path in the case of additional mapping options, which must be specified, allowing only the basePath mapping to be undefined.

Or perhaps we can walk through this example:

declare const acmCertificateForExampleCom: any;
declare const restApi: apigateway.RestApi;
declare const secondRestApi: apigateway.RestApi;
const domain = new apigateway.DomainName(this, 'custom-domain', {
  domainName: 'example.com',
  certificate: acmCertificateForExampleCom,
  mapping: restApi,
});
domain.addApiMapping(secondRestApi.deploymentStage, {
  // not specified, thus undefined, just like above 
});

Which API gets to be called from /?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about apiPath instead? In your example the addApiMapping will throw an error because you are trying to map undefined which has already been mapped when you created the DomainName.

this.addBasePathMapping(props.mapping, {
basePath: props.basePath,
});
} else if (props.mapping && multiLevel) {
this.addApiMapping(props.mapping.deploymentStage, {
basePath: props.basePath,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] The renaming point would (for me) make it easier to read the snippet here.

if (this.endpointType === EndpointType.EDGE) {
throw new Error('multi-level basePath is only supported when endpointType is EndpointType.REGIONAL');
}
if (this.securityPolicy && this.securityPolicy !== SecurityPolicy.TLS_1_2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Should this be a class constant and just referenced here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

@corymhall corymhall removed the pr/do-not-merge This PR should not be merged at this time. label Oct 18, 2022
@mergify
Copy link
Contributor

mergify bot commented Oct 18, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 0fe3a4f
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit cdc5753 into aws:main Oct 19, 2022
@mergify
Copy link
Contributor

mergify bot commented Oct 19, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

mrgrain pushed a commit to mrgrain/aws-cdk that referenced this pull request Oct 24, 2022
…2463)

This PR adds support for multi-level paths in api mappings for custom domains. This is a unique case because in order to create multi-level mappings for RestApis (ApiGateway v1) you have to use the ApiGateway v2 API.

The aws-apigatewayv2 package is currently an alpha module so this cannot depend on that module which is why I used the L1 level to implement this support.

I thought about deprecating the v1 api (BasePathMapping), but that is still a valid API (and is required if you have an EDGE domain name). The experience I landed on was to mostly make it transparent to users. When users create a DomainName, it will now create either a BasePathMapping or an ApiMapping depending on whether they provide a multi-level basePath. I did have to introduce a new `addApiMapping` method since `addBasePathMapping` has a return type of `BasePathMapping`.

I also removed the validation that prevented users from adding additional basePaths if a (none) basePath was already created. It seems like that limitation was removed at some point and I have added an integration test to confirm.

fixes aws#15904


----

### All Submissions:

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

* [ ] 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
contribution/core This is a PR that came from AWS. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-apigateway v1): Support for multi-level paths in BasePathMapping
3 participants