Skip to content

Commit

Permalink
feat(apigateway): disable execute api endpoint (#14526)
Browse files Browse the repository at this point in the history
I noticed that [CloudFormation exposes the field DisableExecuteApiEndpoint on RestApi](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html), but it isn't wired up in CDK (like it is for ApiGatewayv2). This would clean up our infrastructure code quite nicely, were you to accept it into main.

I've verified that CDK omits the field from the CloudFormation (CF) templates if it isn't defined and sets the specified value when it is. I also verified that when those CF templates are deployed to AWS, the default execute endpoint toggle is flipped in API Gateway.

There's also a unit test, I've verified that the fail condition works if the answer is incorrect.

Many thanks.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
spacekitcat authored Jun 11, 2021
1 parent 9718b39 commit b3a7d5b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ export interface RestApiBaseProps {
* @default EndpointType.EDGE
*/
readonly endpointTypes?: EndpointType[];

/**
* Specifies whether clients can invoke the API using the default execute-api
* endpoint. To require that clients use a custom domain name to invoke the
* API, disable the default endpoint.
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html
*
* @default false
*/
readonly disableExecuteApiEndpoint?: boolean;
}

/**
Expand Down Expand Up @@ -719,6 +729,7 @@ export class RestApi extends RestApiBase {
apiKeySourceType: props.apiKeySourceType,
cloneFrom: props.cloneFrom?.restApiId,
parameters: props.parameters,
disableExecuteApiEndpoint: props.disableExecuteApiEndpoint,
});
this.node.defaultChild = resource;
this.restApiId = resource.ref;
Expand Down
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/restapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1069,4 +1069,18 @@ describe('restapi', () => {
expect(countMetric.color).toEqual(color);
});
});

test('"disableExecuteApiEndpoint" can disable the default execute-api endpoint', () => {
// GIVEN
const stack = new Stack();

// WHEN
const api = new apigw.RestApi(stack, 'my-api', { disableExecuteApiEndpoint: true });
api.root.addMethod('GET');

// THEN
expect(stack).toHaveResource('AWS::ApiGateway::RestApi', {
DisableExecuteApiEndpoint: true,
});
});
});

0 comments on commit b3a7d5b

Please sign in to comment.