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): feature flag to disable the default endpoint Output #17239

Conversation

jamesorlakin
Copy link
Contributor

@jamesorlakin jamesorlakin commented Oct 29, 2021

The RestApi construct creates a CfnOutput by default with no exportName. This seems slightly peculiar, and in stacks of my own I've often resorted to myApi.node.tryRemoveChild('Endpoint') to avoid confusion when the deployed APIs are private (and need accessing via a VPC endpoint instead of the normally public HTTPS URL).

It was contemplated in #3662 (comment) to remove this entirely. With CDK v2 providing an opportunity to allow breaking behaviours I've created a new feature flag to gradually introduce this new behaviour. I appreciate breaking changes are never desired, so I'm not disheartened if this is unwanted (feel free to close!).


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 Oct 29, 2021

@github-actions github-actions bot added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Oct 29, 2021
nija-at
nija-at previously requested changes Nov 5, 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 taking the effort to do this.
This is excellent!

Just a couple of small comments.

new CfnOutput(this, 'Endpoint', { exportName: props.endpointExportName, value: this.urlForPath() });
// If the context is true, don't create an unnamed output.
// If false - or the endpointExportName is set, do create a CfnOutput.
const avoidEmptyExport: boolean | undefined = Node.of(this).tryGetContext(APIGATEWAY_REST_API_NO_CFN_OUTPUT);
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooh, nice spot!

@@ -160,6 +160,15 @@ export const LAMBDA_RECOGNIZE_VERSION_PROPS = '@aws-cdk/aws-lambda:recognizeVers
*/
export const CLOUDFRONT_DEFAULT_SECURITY_POLICY_TLS_V1_2_2021 = '@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021';

/**
* API Gateway's REST API construct always creates a CfnOutput with a blank exportName. That name can be overridden
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
* API Gateway's REST API construct always creates a CfnOutput with a blank exportName. That name can be overridden
* API Gateway's RestApi construct always creates a CfnOutput with a blank exportName. That name can be overridden

@mergify mergify bot dismissed nija-at’s stale review November 8, 2021 09:37

Pull request has been modified.

@jamesorlakin jamesorlakin force-pushed the refactor/api-gateway-no-default-cfnoutput branch from 2796584 to bf96867 Compare November 8, 2021 09:38
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: d7f7887
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@nija-at nija-at changed the title fix(aws-apigateway): RestApi no longer creates a CfnOutput by default (under feature flag) fix(apigateway): feature flag to disable the default endpoint Output Nov 9, 2021
@nija-at nija-at changed the title fix(apigateway): feature flag to disable the default endpoint Output feat(apigateway): feature flag to disable the default endpoint Output Nov 9, 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.

I'm curious about one thing - why did you pick the feature flag option, rather than just provide an option to disable this (enabled by default)?

@jamesorlakin
Copy link
Contributor Author

That's an excellent question! I'll be honest and say I didn't think about doing that 🤦‍♂️

An extra boolean prop like avoidEndpointExport could work, then it could throw if provided a endpointExportName as well. While the default of having an output seems a little odd I guess it's not a breaking change by any stretch.

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.

@jamesorlakin - feels to me like the simpler solution than introducing a feature flag.

I can see you've put in a considerable amount of work to get the feature flag going, especially given that this is a tricky part of our code base, but would you consider switching up the solution?

@jamesorlakin
Copy link
Contributor Author

Hey @nija-at, that's honestly fine and no worries - good thinking of a much simpler solution!

I'll close this one and maybe make something similar to the deploy prop (default true) when I get around to it.

@olka-dev
Copy link

olka-dev commented Feb 25, 2022

@jamesorlakin you have not got around it in the end, haven`t you?...
You could have saved my day with this feature flag.
Unfortunately you were stopped before merging, @nija-at big thanks there... 🤬
Gotta have to go with node.findChild then.

@jamesorlakin
Copy link
Contributor Author

...nope, it fell off my radar. You can always open a PR if you're that passionate about it. 👀

Otherwise a one-liner tryRemoveChild is far from the end of the world. Subclass with this behaviour if there's many RestApi instances and you don't want repetition in other constructs.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants