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

8 changes: 6 additions & 2 deletions packages/@aws-cdk/aws-apigateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,9 @@ By default, the `RestApi` construct will automatically create an API Gateway
defined in your CDK app. This means that when you deploy your app, your API will
be have open access from the internet via the stage URL.

The URL of your API can be obtained from the attribute `restApi.url`, and is
also exported as an `Output` from your stack, so it's printed when you `cdk
The URL of your API can be obtained from the attribute `restApi.url`. If the
context `@aws-cdk/aws-apigateway:noDefaultRestApiCfnOutput` is `false` it will
also be exported as an `Output` from your stack, so it's printed when you `cdk
deploy` your app:

```console
Expand All @@ -699,6 +700,9 @@ $ cdk deploy
books.booksapiEndpointE230E8D5 = https://6lyktd4lpk.execute-api.us-east-1.amazonaws.com/prod/
```

If the context is true (by default in new projects) then an output is only created
when specifying the `endpointExportName` property.

To disable this behavior, you can set `{ deploy: false }` when creating your
API. This means that the API will not be deployed and a stage will not be
created for it. You will need to manually define a `apigateway.Deployment` and
Expand Down
16 changes: 12 additions & 4 deletions packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
import { IVpcEndpoint } from '@aws-cdk/aws-ec2';
import * as iam from '@aws-cdk/aws-iam';
import { CfnOutput, IResource as IResourceBase, Resource, Stack } from '@aws-cdk/core';
import { CfnOutput, IResource as IResourceBase, Resource, Stack, FeatureFlags } from '@aws-cdk/core';
import { APIGATEWAY_REST_API_NO_CFN_OUTPUT } from '@aws-cdk/cx-api';
import { Construct } from 'constructs';
import { ApiDefinition } from './api-definition';
import { ApiKey, ApiKeyOptions, IApiKey } from './api-key';
Expand Down Expand Up @@ -157,9 +158,11 @@ export interface RestApiBaseProps {
readonly cloudWatchRole?: boolean;

/**
* Export name for the CfnOutput containing the API endpoint
* Export name for the CfnOutput containing the API endpoint.
*
* @default - when no export name is given, output will be created without export
* @default - If the `@aws-cdk/aws-apigateway:noDefaultRestApiCfnOutput`
* context is true no output will be created. If false, an output will be
* created but with an undefined export name.
*/
readonly endpointExportName?: string;

Expand Down Expand Up @@ -551,7 +554,12 @@ export abstract class RestApiBase extends Resource implements IRestApi {
...props.deployOptions,
});

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 = FeatureFlags.of(this).isEnabled(APIGATEWAY_REST_API_NO_CFN_OUTPUT);
if (props.endpointExportName || avoidEmptyExport !== true) {
new CfnOutput(this, 'Endpoint', { exportName: props.endpointExportName, value: this.urlForPath() });
}
} else {
if (props.deployOptions) {
throw new Error('Cannot set \'deployOptions\' if \'deploy\' is disabled');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,33 +161,5 @@
]
}
}
},
"Outputs": {
"myrestapiEndpointE06F9D98": {
"Value": {
"Fn::Join": [
"",
[
"https://",
{
"Ref": "myrestapi551C8392"
},
".execute-api.",
{
"Ref": "AWS::Region"
},
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Ref": "myrestapiDeploymentStageprodA9250EA4"
},
"/"
]
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@
]
}
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"MyAuthorizerFunctionServiceRole8A34C19E",
"Arn"
]
},
"Handler": "index.handler",
"Runtime": "nodejs10.x"
},
"DependsOn": [
Expand Down Expand Up @@ -284,33 +284,5 @@
"Type": "String",
"Description": "Artifact hash for asset \"3dc8c5549b88fef617feef923524902b3650973ae1159c9489ee8405344dd5a0\""
}
},
"Outputs": {
"MyRestApiEndpoint4C55E4CB": {
"Value": {
"Fn::Join": [
"",
[
"https://",
{
"Ref": "MyRestApi2D1F47A9"
},
".execute-api.",
{
"Ref": "AWS::Region"
},
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Ref": "MyRestApiDeploymentStageprodC33B8E5F"
},
"/"
]
]
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@
]
}
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"MyAuthorizerFunctionServiceRole8A34C19E",
"Arn"
]
},
"Handler": "index.handler",
"Runtime": "nodejs10.x"
},
"DependsOn": [
Expand Down Expand Up @@ -293,33 +293,5 @@
"Type": "String",
"Description": "Artifact hash for asset \"fec8e8354e12687c5a4b843b4e269741f53dec634946869b276f7fd1017845c3\""
}
},
"Outputs": {
"MyRestApiEndpoint4C55E4CB": {
"Value": {
"Fn::Join": [
"",
[
"https://",
{
"Ref": "MyRestApi2D1F47A9"
},
".execute-api.",
{
"Ref": "AWS::Region"
},
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Ref": "MyRestApiDeploymentStageprodC33B8E5F"
},
"/"
]
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@
]
}
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"MyAuthorizerFunctionServiceRole8A34C19E",
"Arn"
]
},
"Handler": "index.handler",
"Runtime": "nodejs10.x"
},
"DependsOn": [
Expand Down Expand Up @@ -284,33 +284,5 @@
"Type": "String",
"Description": "Artifact hash for asset \"fec8e8354e12687c5a4b843b4e269741f53dec634946869b276f7fd1017845c3\""
}
},
"Outputs": {
"MyRestApiEndpoint4C55E4CB": {
"Value": {
"Fn::Join": [
"",
[
"https://",
{
"Ref": "MyRestApi2D1F47A9"
},
".execute-api.",
{
"Ref": "AWS::Region"
},
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Ref": "MyRestApiDeploymentStageprodC33B8E5F"
},
"/"
]
]
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,33 +160,21 @@
]
}
},
"Outputs": {
"myapiEndpoint3628AFE3": {
"Value": {
"Fn::Join": [
"",
[
"https://",
{
"Ref": "myapi4C7BF186"
},
".execute-api.",
{
"Ref": "AWS::Region"
},
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Ref": "myapiDeploymentStageprod298F01AF"
},
"/"
]
]
}
"Parameters": {
"AssetParameters68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fbS3Bucket42039E29": {
"Type": "String",
"Description": "S3 bucket for asset \"68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fb\""
},
"AssetParameters68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fbS3VersionKeyB590532F": {
"Type": "String",
"Description": "S3 key for asset version \"68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fb\""
},
"AssetParameters68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fbArtifactHashA9C91B6D": {
"Type": "String",
"Description": "Artifact hash for asset \"68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fb\""
}
},
"Outputs": {
"PetsURL": {
"Value": {
"Fn::Join": [
Expand Down Expand Up @@ -239,19 +227,5 @@
]
}
}
},
"Parameters": {
"AssetParameters68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fbS3Bucket42039E29": {
"Type": "String",
"Description": "S3 bucket for asset \"68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fb\""
},
"AssetParameters68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fbS3VersionKeyB590532F": {
"Type": "String",
"Description": "S3 key for asset version \"68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fb\""
},
"AssetParameters68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fbArtifactHashA9C91B6D": {
"Type": "String",
"Description": "Artifact hash for asset \"68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fb\""
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,32 +121,6 @@
}
},
"Outputs": {
"myapiEndpoint3628AFE3": {
"Value": {
"Fn::Join": [
"",
[
"https://",
{
"Ref": "myapi4C7BF186"
},
".execute-api.",
{
"Ref": "AWS::Region"
},
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Ref": "myapiDeploymentStageprod298F01AF"
},
"/"
]
]
}
},
"PetsURL": {
"Value": {
"Fn::Join": [
Expand Down
30 changes: 1 addition & 29 deletions packages/@aws-cdk/aws-apigateway/test/integ.cors.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -564,48 +564,20 @@
]
}
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"handlerServiceRole187D5A5A",
"Arn"
]
},
"Handler": "index.handler",
"Runtime": "nodejs10.x"
},
"DependsOn": [
"handlerServiceRole187D5A5A"
]
}
},
"Outputs": {
"corsapitestEndpointE63606AE": {
"Value": {
"Fn::Join": [
"",
[
"https://",
{
"Ref": "corsapitest8682546E"
},
".execute-api.",
{
"Ref": "AWS::Region"
},
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Ref": "corsapitestDeploymentStageprod8F31F2AB"
},
"/"
]
]
}
}
},
"Parameters": {
"AssetParametersc7bba0d9d477c86c6dc2adb0eb95842634a1c040dd3a66b42eec2bb604644d4fS3BucketE85F411C": {
"Type": "String",
Expand Down
Loading