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(apigatewayv2): http api - domain url for a stage #15973

Merged
merged 8 commits into from
Aug 12, 2021

Conversation

samtwil
Copy link
Contributor

@samtwil samtwil commented Aug 10, 2021

Closes #15801

By adding and apiMapping field to base.ts, we can reference the custom domain information from the HttpStage construct


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Aug 10, 2021

@peterwoodworth peterwoodworth added @aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 effort/small Small work item – less than a day of effort labels Aug 11, 2021
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this PR. Please see my comments below.

Comment on lines 85 to 88
/**
* API domain name
*/
public readonly domainName?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be optional.

Why not just set the type to IDomainName instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I've updated the type here

packages/@aws-cdk/aws-apigatewayv2/lib/common/base.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/lib/http/stage.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2/test/http/stage.test.ts Outdated Show resolved Hide resolved
…rror if _addDomainMapping() is called more than once, and renamed customDomainUrl to domainUrl
@mergify mergify bot dismissed nija-at’s stale review August 12, 2021 15:25

Pull request has been modified.

Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @samtwil. See a few more comments below.

packages/@aws-cdk/aws-apigatewayv2/lib/common/base.ts Outdated Show resolved Hide resolved
@@ -45,7 +50,10 @@ export abstract class StageBase extends Resource implements IStage {
* @internal
*/
protected _addDomainMapping(domainMapping: DomainMappingOptions) {
new ApiMapping(this, `${domainMapping.domainName}${domainMapping.mappingKey}`, {
if (this.apiMapping) {
throw new Error('_addDomainMapping cannot be called more than once for a Stage');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
throw new Error('_addDomainMapping cannot be called more than once for a Stage');
throw new Error('Only one ApiMapping allowed per Stage');

Copy link
Contributor

Choose a reason for hiding this comment

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

Add a test case for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nija-at What is the recommended pattern for testing a protected function?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see the problem, it might be a bit convoluted.
I think it's fine to skip the test case for this. Sorry for the mixed message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a problem! Thanks for the response

packages/@aws-cdk/aws-apigatewayv2/lib/http/stage.ts Outdated Show resolved Hide resolved
Comment on lines 187 to 189
if (!this.apiMapping.domainName.name) {
throw new Error('Unable to build domainUrl due to invalid domainName');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't need this anymore now that domainName is not optional, right?

If the check is for domainName being empty string (indicated by your test case),
(a) I wonder if empty string domain names are valid strings. Perhaps disallow it in the CDK?
(b) update the message to be more clear, i.e., what is invalid about it.

Copy link
Contributor Author

@samtwil samtwil Aug 12, 2021

Choose a reason for hiding this comment

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

It doesn't appear that the aws cli command for creating an API Mapping allows for an empty string after some testing.

Should I update the ApiMapping or DomainName constructor to throw this error?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that would be preferrable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nija-at I had updated my comment perhaps after you read it. Which class constructor should I put this error in? ApiMapping or DomainName?

DomainName would catch the error earlier, but I want to check with you before I proceed.

Copy link
Contributor

Choose a reason for hiding this comment

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

DomainName sounds like the right spot.

packages/@aws-cdk/aws-apigatewayv2/test/http/stage.test.ts Outdated Show resolved Hide resolved
@nija-at nija-at changed the title feat(apigatewayv2): added support for customDomainUrl property to stage feat(apigatewayv2): http api - domain url for a stage Aug 12, 2021
@nija-at
Copy link
Contributor

nija-at commented Aug 12, 2021

Could you also make an entry in the README as indicated by the linter?

samtwil and others added 3 commits August 12, 2021 12:41
Co-authored-by: Niranjan Jayakar <nija@amazon.com>
Co-authored-by: Niranjan Jayakar <nija@amazon.com>
Co-authored-by: Niranjan Jayakar <nija@amazon.com>
@mergify mergify bot dismissed nija-at’s stale review August 12, 2021 17:42

Pull request has been modified.

@samtwil
Copy link
Contributor Author

samtwil commented Aug 12, 2021

Could you also make an entry in the README as indicated by the linter?

Done. Please let me know if there is any further detail I need to provide here

Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

@samtwil - Everything looks good. I'm approving this change.

I would appreciate if you can submit a separate PR to disallow empty string as domain names.

@mergify
Copy link
Contributor

mergify bot commented Aug 12, 2021

Thank you for contributing! Your pull request will be updated from master 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: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 33765f4
  • 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 bb5d587 into aws:master Aug 12, 2021
@mergify
Copy link
Contributor

mergify bot commented Aug 12, 2021

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

@samtwil samtwil deleted the feat-apigatewayv2-stage-customdomainurl branch August 12, 2021 21:00
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
Closes aws#15801 

By adding and `apiMapping` field to base.ts, we can reference the custom domain information from the `HttpStage` construct

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
david-doyle-as24 pushed a commit to david-doyle-as24/aws-cdk that referenced this pull request Sep 7, 2021
Closes aws#15801 

By adding and `apiMapping` field to base.ts, we can reference the custom domain information from the `HttpStage` construct

----

*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-apigatewayv2 Related to Amazon API Gateway v2 effort/small Small work item – less than a day of effort
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(apigatewayv2): get custom domain url for a given stage
4 participants