From 2a81f0f7d9eb73cd0e807904357a5daf7d6e5017 Mon Sep 17 00:00:00 2001 From: pattasai <121061922+pattasai@users.noreply.github.com> Date: Wed, 1 Mar 2023 11:09:34 -0500 Subject: [PATCH] feat(apigateway): minCompressionSize on SpecRestApi (#24067) This PR adds minCompressionSize to SpecRestApi, which allows compression on api's payload. Within SpecRestApi ``` minComppresssionSize: Size``` is the additional prop added to SpecRestApiProps to support minCompressionSize which takes class Size, the value of how much the payload needs to be compressed. This PR also adds minCompressionSize to RestApi which supports Size class e.g ``` minComppresssionSize: Size``` and deprecates minimumCompressionSize which has number as a type. For example, ```ts const api = new apigw.RestApi(stack, 'RestApi', { minCompressionSize: Size.bytes(1024), }); ``` compression for the payload would be 1024 bytes which is equivalent to 1 kibibyte. Closes #22926. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../@aws-cdk/aws-apigateway/lib/restapi.ts | 34 +- ...efaultTestDeployAssert6A9696A7.assets.json | 2 +- .../test/integ.restapi.js.snapshot/cdk.out | 2 +- .../test/integ.restapi.js.snapshot/integ.json | 2 +- .../integ.restapi.js.snapshot/manifest.json | 37 +- .../test-apigateway-restapi.assets.json | 6 +- .../test-apigateway-restapi.template.json | 9 +- .../test/integ.restapi.js.snapshot/tree.json | 73 +++- .../aws-apigateway/test/integ.restapi.ts | 2 + ...efaultTestDeployAssertD16AA485.assets.json | 2 +- .../integ.spec-restapi.js.snapshot/cdk.out | 2 +- .../integ.spec-restapi.js.snapshot/integ.json | 2 +- .../manifest.json | 27 +- .../test-apigateway-spec-restapi.assets.json | 6 +- ...test-apigateway-spec-restapi.template.json | 5 +- .../integ.spec-restapi.js.snapshot/tree.json | 71 +++- .../aws-apigateway/test/integ.spec-restapi.ts | 2 + .../aws-apigateway/test/restapi.test.ts | 347 +++++++++++------- 18 files changed, 429 insertions(+), 202 deletions(-) diff --git a/packages/@aws-cdk/aws-apigateway/lib/restapi.ts b/packages/@aws-cdk/aws-apigateway/lib/restapi.ts index 7f44eddaf0ca9..41a0990e4f5f7 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/restapi.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/restapi.ts @@ -1,7 +1,7 @@ import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; import { IVpcEndpoint } from '@aws-cdk/aws-ec2'; import * as iam from '@aws-cdk/aws-iam'; -import { ArnFormat, CfnOutput, IResource as IResourceBase, Resource, Stack, Token, FeatureFlags, RemovalPolicy } from '@aws-cdk/core'; +import { ArnFormat, CfnOutput, IResource as IResourceBase, Resource, Stack, Token, FeatureFlags, RemovalPolicy, Size } from '@aws-cdk/core'; import { APIGATEWAY_DISABLE_CLOUDWATCH_ROLE } from '@aws-cdk/cx-api'; import { Construct } from 'constructs'; import { ApiDefinition } from './api-definition'; @@ -225,9 +225,22 @@ export interface RestApiProps extends RestApiOptions { * payload size. * * @default - Compression is disabled. + * @deprecated - superseded by `minCompressionSize` */ readonly minimumCompressionSize?: number; + /** + * A Size(in bytes, kibibytes, mebibytes etc) that is used to enable compression (with non-negative + * between 0 and 10485760 (10M) bytes, inclusive) or disable compression + * (when undefined) on an API. When compression is enabled, compression or + * decompression is not applied on the payload if the payload size is + * smaller than this value. Setting it to zero allows compression for any + * payload size. + * + * @default - Compression is disabled. + */ + readonly minCompressionSize?: Size; + /** * The ID of the API Gateway RestApi resource that you want to clone. * @@ -261,6 +274,18 @@ export interface SpecRestApiProps extends RestApiBaseProps { * @see https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-import-api.html */ readonly apiDefinition: ApiDefinition; + + /** + * A Size(in bytes, kibibytes, mebibytes etc) that is used to enable compression (with non-negative + * between 0 and 10485760 (10M) bytes, inclusive) or disable compression + * (when undefined) on an API. When compression is enabled, compression or + * decompression is not applied on the payload if the payload size is + * smaller than this value. Setting it to zero allows compression for any + * payload size. + * + * @default - Compression is disabled. + */ + readonly minCompressionSize?: Size; } /** @@ -648,6 +673,7 @@ export class SpecRestApi extends RestApiBase { name: this.restApiName, policy: props.policy, failOnWarnings: props.failOnWarnings, + minimumCompressionSize: props.minCompressionSize?.toBytes(), body: apiDefConfig.inlineDefinition ?? undefined, bodyS3Location: apiDefConfig.inlineDefinition ? undefined : apiDefConfig.s3Location, endpointConfiguration: this._configureEndpoints(props), @@ -758,12 +784,16 @@ export class RestApi extends RestApiBase { constructor(scope: Construct, id: string, props: RestApiProps = { }) { super(scope, id, props); + if (props.minCompressionSize !== undefined && props.minimumCompressionSize !== undefined) { + throw new Error('both properties minCompressionSize and minimumCompressionSize cannot be set at once.'); + } + const resource = new CfnRestApi(this, 'Resource', { name: this.physicalName, description: props.description, policy: props.policy, failOnWarnings: props.failOnWarnings, - minimumCompressionSize: props.minimumCompressionSize, + minimumCompressionSize: props.minCompressionSize?.toBytes() ?? props.minimumCompressionSize, binaryMediaTypes: props.binaryMediaTypes, endpointConfiguration: this._configureEndpoints(props), apiKeySourceType: props.apiKeySourceType, diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/apigatewayrestapiDefaultTestDeployAssert6A9696A7.assets.json b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/apigatewayrestapiDefaultTestDeployAssert6A9696A7.assets.json index 40422419875ec..0a13f744eed97 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/apigatewayrestapiDefaultTestDeployAssert6A9696A7.assets.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/apigatewayrestapiDefaultTestDeployAssert6A9696A7.assets.json @@ -1,5 +1,5 @@ { - "version": "21.0.0", + "version": "30.0.0", "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/cdk.out b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/cdk.out index 8ecc185e9dbee..ae4b03c54e770 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/cdk.out +++ b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"21.0.0"} \ No newline at end of file +{"version":"30.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/integ.json b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/integ.json index ab9a770171263..67626e9b771eb 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/integ.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "21.0.0", + "version": "30.0.0", "testCases": { "apigateway-restapi/DefaultTest": { "stacks": [ diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/manifest.json b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/manifest.json index ec6db85280ab2..382751142abcf 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/manifest.json @@ -1,12 +1,6 @@ { - "version": "21.0.0", + "version": "30.0.0", "artifacts": { - "Tree": { - "type": "cdk:tree", - "properties": { - "file": "tree.json" - } - }, "test-apigateway-restapi.assets": { "type": "cdk:asset-manifest", "properties": { @@ -23,7 +17,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/527feb6f65d1f41404abb6acfb6504a918e1d7489665b74acb9fa0ca23f34049.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/94f416193221135915e06201345d08e3db001c8bbf22b073f16ec02d3b8fba4b.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -60,7 +54,7 @@ "/test-apigateway-restapi/my-api/Deployment/Resource": [ { "type": "aws:cdk:logicalId", - "data": "myapiDeployment92F2CB4996088bac04ec19d9db88f146f3d88bca" + "data": "myapiDeployment92F2CB496a6dee9579dae89ab3a0b094b4d193eb" } ], "/test-apigateway-restapi/my-api/DeploymentStage.beta/Resource": [ @@ -204,7 +198,7 @@ "/test-apigateway-restapi/TestDeployment/Resource": [ { "type": "aws:cdk:logicalId", - "data": "TestDeploymentD77B56866f3141cef1e8fea8ab3b3b8bc90df36d" + "data": "TestDeploymentD77B56860a9c34c1bc306bfbc7d318827eacd1e1" } ], "/test-apigateway-restapi/TestStage/Resource": [ @@ -231,28 +225,19 @@ "data": "CheckBootstrapVersion" } ], - "myapiDeployment92F2CB4963d40685c54c6f8da21d80a83f16d3d5": [ + "myapiDeployment92F2CB4996088bac04ec19d9db88f146f3d88bca": [ { "type": "aws:cdk:logicalId", - "data": "myapiDeployment92F2CB4963d40685c54c6f8da21d80a83f16d3d5", + "data": "myapiDeployment92F2CB4996088bac04ec19d9db88f146f3d88bca", "trace": [ "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" ] } ], - "myapiv1appliances507FEFF4": [ + "TestDeploymentD77B56866f3141cef1e8fea8ab3b3b8bc90df36d": [ { "type": "aws:cdk:logicalId", - "data": "myapiv1appliances507FEFF4", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] - } - ], - "myapiv1appliancesGET8FE872EC": [ - { - "type": "aws:cdk:logicalId", - "data": "myapiv1appliancesGET8FE872EC", + "data": "TestDeploymentD77B56866f3141cef1e8fea8ab3b3b8bc90df36d", "trace": [ "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" ] @@ -307,6 +292,12 @@ ] }, "displayName": "apigateway-restapi/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/test-apigateway-restapi.assets.json b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/test-apigateway-restapi.assets.json index b397476ca59d6..09a88ca2b52e8 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/test-apigateway-restapi.assets.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/test-apigateway-restapi.assets.json @@ -1,7 +1,7 @@ { - "version": "21.0.0", + "version": "30.0.0", "files": { - "527feb6f65d1f41404abb6acfb6504a918e1d7489665b74acb9fa0ca23f34049": { + "94f416193221135915e06201345d08e3db001c8bbf22b073f16ec02d3b8fba4b": { "source": { "path": "test-apigateway-restapi.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "527feb6f65d1f41404abb6acfb6504a918e1d7489665b74acb9fa0ca23f34049.json", + "objectKey": "94f416193221135915e06201345d08e3db001c8bbf22b073f16ec02d3b8fba4b.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/test-apigateway-restapi.template.json b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/test-apigateway-restapi.template.json index 1e9121a7471dc..43a8699e33d49 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/test-apigateway-restapi.template.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/test-apigateway-restapi.template.json @@ -3,6 +3,7 @@ "myapi4C7BF186": { "Type": "AWS::ApiGateway::RestApi", "Properties": { + "MinimumCompressionSize": 1024, "Name": "my-api" } }, @@ -55,7 +56,7 @@ "UpdateReplacePolicy": "Retain", "DeletionPolicy": "Retain" }, - "myapiDeployment92F2CB4996088bac04ec19d9db88f146f3d88bca": { + "myapiDeployment92F2CB496a6dee9579dae89ab3a0b094b4d193eb": { "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { @@ -87,7 +88,7 @@ "CacheClusterEnabled": true, "CacheClusterSize": "0.5", "DeploymentId": { - "Ref": "myapiDeployment92F2CB4996088bac04ec19d9db88f146f3d88bca" + "Ref": "myapiDeployment92F2CB496a6dee9579dae89ab3a0b094b4d193eb" }, "Description": "beta stage", "MethodSettings": [ @@ -672,7 +673,7 @@ "MyHandlerServiceRoleFFA06653" ] }, - "TestDeploymentD77B56866f3141cef1e8fea8ab3b3b8bc90df36d": { + "TestDeploymentD77B56860a9c34c1bc306bfbc7d318827eacd1e1": { "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { @@ -695,7 +696,7 @@ "Ref": "myapi4C7BF186" }, "DeploymentId": { - "Ref": "TestDeploymentD77B56866f3141cef1e8fea8ab3b3b8bc90df36d" + "Ref": "TestDeploymentD77B56860a9c34c1bc306bfbc7d318827eacd1e1" }, "StageName": "prod" }, diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/tree.json b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/tree.json index c4920b5ecffdf..3bf0e3cc25e09 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.js.snapshot/tree.json @@ -4,14 +4,6 @@ "id": "App", "path": "", "children": { - "Tree": { - "id": "Tree", - "path": "Tree", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.129" - } - }, "test-apigateway-restapi": { "id": "test-apigateway-restapi", "path": "test-apigateway-restapi", @@ -26,6 +18,7 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::ApiGateway::RestApi", "aws:cdk:cloudformation:props": { + "minimumCompressionSize": 1024, "name": "my-api" } }, @@ -38,6 +31,14 @@ "id": "CloudWatchRole", "path": "test-apigateway-restapi/my-api/CloudWatchRole", "children": { + "ImportCloudWatchRole": { + "id": "ImportCloudWatchRole", + "path": "test-apigateway-restapi/my-api/CloudWatchRole/ImportCloudWatchRole", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, "Resource": { "id": "Resource", "path": "test-apigateway-restapi/my-api/CloudWatchRole/Resource", @@ -145,7 +146,7 @@ "cacheClusterEnabled": true, "cacheClusterSize": "0.5", "deploymentId": { - "Ref": "myapiDeployment92F2CB4996088bac04ec19d9db88f146f3d88bca" + "Ref": "myapiDeployment92F2CB496a6dee9579dae89ab3a0b094b4d193eb" }, "description": "beta stage", "methodSettings": [ @@ -992,6 +993,14 @@ "id": "ServiceRole", "path": "test-apigateway-restapi/MyHandler/ServiceRole", "children": { + "ImportServiceRole": { + "id": "ImportServiceRole", + "path": "test-apigateway-restapi/MyHandler/ServiceRole/ImportServiceRole", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, "Resource": { "id": "Resource", "path": "test-apigateway-restapi/MyHandler/ServiceRole/Resource", @@ -1107,7 +1116,7 @@ "Ref": "myapi4C7BF186" }, "deploymentId": { - "Ref": "TestDeploymentD77B56866f3141cef1e8fea8ab3b3b8bc90df36d" + "Ref": "TestDeploymentD77B56860a9c34c1bc306bfbc7d318827eacd1e1" }, "stageName": "prod" } @@ -1156,6 +1165,22 @@ "fqn": "@aws-cdk/aws-apigateway.Stage", "version": "0.0.0" } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "test-apigateway-restapi/BootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "test-apigateway-restapi/CheckBootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnRule", + "version": "0.0.0" + } } }, "constructInfo": { @@ -1176,12 +1201,30 @@ "path": "apigateway-restapi/DefaultTest/Default", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.1.129" + "version": "10.1.249" } }, "DeployAssert": { "id": "DeployAssert", "path": "apigateway-restapi/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "apigateway-restapi/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "apigateway-restapi/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnRule", + "version": "0.0.0" + } + } + }, "constructInfo": { "fqn": "@aws-cdk/core.Stack", "version": "0.0.0" @@ -1198,6 +1241,14 @@ "fqn": "@aws-cdk/integ-tests.IntegTest", "version": "0.0.0" } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.249" + } } }, "constructInfo": { diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.ts b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.ts index 4a2373e9d6aa9..47030c17160fe 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.ts +++ b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.ts @@ -1,5 +1,6 @@ import * as lambda from '@aws-cdk/aws-lambda'; import * as cdk from '@aws-cdk/core'; +import { Size } from '@aws-cdk/core'; import { IntegTest } from '@aws-cdk/integ-tests'; import * as apigateway from '../lib'; @@ -10,6 +11,7 @@ class Test extends cdk.Stack { const api = new apigateway.RestApi(this, 'my-api', { retainDeployments: true, cloudWatchRole: true, + minCompressionSize: Size.bytes(1024), deployOptions: { cacheClusterEnabled: true, stageName: 'beta', diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/apigatewayspecrestapiDefaultTestDeployAssertD16AA485.assets.json b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/apigatewayspecrestapiDefaultTestDeployAssertD16AA485.assets.json index 7c4a2beda03b5..eae4994100f87 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/apigatewayspecrestapiDefaultTestDeployAssertD16AA485.assets.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/apigatewayspecrestapiDefaultTestDeployAssertD16AA485.assets.json @@ -1,5 +1,5 @@ { - "version": "21.0.0", + "version": "30.0.0", "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/cdk.out b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/cdk.out index 8ecc185e9dbee..ae4b03c54e770 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/cdk.out +++ b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"21.0.0"} \ No newline at end of file +{"version":"30.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/integ.json b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/integ.json index f4c240596beb4..27ab5a7e80179 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/integ.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "21.0.0", + "version": "30.0.0", "testCases": { "apigateway-spec-restapi/DefaultTest": { "stacks": [ diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/manifest.json b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/manifest.json index ec86acb97e7a9..1112099915ed4 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/manifest.json @@ -1,12 +1,6 @@ { - "version": "21.0.0", + "version": "30.0.0", "artifacts": { - "Tree": { - "type": "cdk:tree", - "properties": { - "file": "tree.json" - } - }, "test-apigateway-spec-restapi.assets": { "type": "cdk:asset-manifest", "properties": { @@ -23,7 +17,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/4b4324bd66c0a5352124c718d0cb3990046afe7ccf1cea94d4488ed7cd67191b.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/a361f357c68964992ee5038aa363d75be98e145d828b8955269361c54d7722ae.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -156,7 +150,7 @@ "/test-apigateway-spec-restapi/my-api/Deployment/Resource": [ { "type": "aws:cdk:logicalId", - "data": "myapiDeployment92F2CB49e2ce3595b92ff44fad021c2e55149db1" + "data": "myapiDeployment92F2CB492c49d8fa05ada8b5cddee1ce76138bd0" } ], "/test-apigateway-spec-restapi/my-api/DeploymentStage.beta/Resource": [ @@ -212,6 +206,15 @@ "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } + ], + "myapiDeployment92F2CB49e2ce3595b92ff44fad021c2e55149db1": [ + { + "type": "aws:cdk:logicalId", + "data": "myapiDeployment92F2CB49e2ce3595b92ff44fad021c2e55149db1", + "trace": [ + "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" + ] + } ] }, "displayName": "test-apigateway-spec-restapi" @@ -262,6 +265,12 @@ ] }, "displayName": "apigateway-spec-restapi/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/test-apigateway-spec-restapi.assets.json b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/test-apigateway-spec-restapi.assets.json index 2bff91cb920f7..54d375c1f6975 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/test-apigateway-spec-restapi.assets.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/test-apigateway-spec-restapi.assets.json @@ -1,5 +1,5 @@ { - "version": "21.0.0", + "version": "30.0.0", "files": { "68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fb": { "source": { @@ -14,7 +14,7 @@ } } }, - "4b4324bd66c0a5352124c718d0cb3990046afe7ccf1cea94d4488ed7cd67191b": { + "a361f357c68964992ee5038aa363d75be98e145d828b8955269361c54d7722ae": { "source": { "path": "test-apigateway-spec-restapi.template.json", "packaging": "file" @@ -22,7 +22,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "4b4324bd66c0a5352124c718d0cb3990046afe7ccf1cea94d4488ed7cd67191b.json", + "objectKey": "a361f357c68964992ee5038aa363d75be98e145d828b8955269361c54d7722ae.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/test-apigateway-spec-restapi.template.json b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/test-apigateway-spec-restapi.template.json index 5214b610b9995..219437fc11d7c 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/test-apigateway-spec-restapi.template.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/test-apigateway-spec-restapi.template.json @@ -10,6 +10,7 @@ "Key": "68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fb.yaml" }, "DisableExecuteApiEndpoint": true, + "MinimumCompressionSize": 1024, "Name": "my-api" } }, @@ -516,7 +517,7 @@ "UpdateReplacePolicy": "Retain", "DeletionPolicy": "Retain" }, - "myapiDeployment92F2CB49e2ce3595b92ff44fad021c2e55149db1": { + "myapiDeployment92F2CB492c49d8fa05ada8b5cddee1ce76138bd0": { "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { @@ -548,7 +549,7 @@ "CacheClusterEnabled": true, "CacheClusterSize": "0.5", "DeploymentId": { - "Ref": "myapiDeployment92F2CB49e2ce3595b92ff44fad021c2e55149db1" + "Ref": "myapiDeployment92F2CB492c49d8fa05ada8b5cddee1ce76138bd0" }, "Description": "beta stage", "MethodSettings": [ diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/tree.json b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/tree.json index 10cba98b03d1a..2dd509aaa2020 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.js.snapshot/tree.json @@ -4,14 +4,6 @@ "id": "App", "path": "", "children": { - "Tree": { - "id": "Tree", - "path": "Tree", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.140" - } - }, "test-apigateway-spec-restapi": { "id": "test-apigateway-spec-restapi", "path": "test-apigateway-spec-restapi", @@ -59,6 +51,7 @@ "key": "68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fb.yaml" }, "disableExecuteApiEndpoint": true, + "minimumCompressionSize": 1024, "name": "my-api" } }, @@ -763,6 +756,14 @@ "id": "CloudWatchRole", "path": "test-apigateway-spec-restapi/my-api/CloudWatchRole", "children": { + "ImportCloudWatchRole": { + "id": "ImportCloudWatchRole", + "path": "test-apigateway-spec-restapi/my-api/CloudWatchRole/ImportCloudWatchRole", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, "Resource": { "id": "Resource", "path": "test-apigateway-spec-restapi/my-api/CloudWatchRole/Resource", @@ -870,7 +871,7 @@ "cacheClusterEnabled": true, "cacheClusterSize": "0.5", "deploymentId": { - "Ref": "myapiDeployment92F2CB49e2ce3595b92ff44fad021c2e55149db1" + "Ref": "myapiDeployment92F2CB492c49d8fa05ada8b5cddee1ce76138bd0" }, "description": "beta stage", "methodSettings": [ @@ -1025,6 +1026,14 @@ "id": "ServiceRole", "path": "test-apigateway-spec-restapi/MyHandler/ServiceRole", "children": { + "ImportServiceRole": { + "id": "ImportServiceRole", + "path": "test-apigateway-spec-restapi/MyHandler/ServiceRole/ImportServiceRole", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, "Resource": { "id": "Resource", "path": "test-apigateway-spec-restapi/MyHandler/ServiceRole/Resource", @@ -1099,6 +1108,22 @@ "fqn": "@aws-cdk/aws-lambda.Function", "version": "0.0.0" } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "test-apigateway-spec-restapi/BootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "test-apigateway-spec-restapi/CheckBootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnRule", + "version": "0.0.0" + } } }, "constructInfo": { @@ -1119,12 +1144,30 @@ "path": "apigateway-spec-restapi/DefaultTest/Default", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.1.140" + "version": "10.1.249" } }, "DeployAssert": { "id": "DeployAssert", "path": "apigateway-spec-restapi/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "apigateway-spec-restapi/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "apigateway-spec-restapi/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnRule", + "version": "0.0.0" + } + } + }, "constructInfo": { "fqn": "@aws-cdk/core.Stack", "version": "0.0.0" @@ -1141,6 +1184,14 @@ "fqn": "@aws-cdk/integ-tests.IntegTest", "version": "0.0.0" } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.249" + } } }, "constructInfo": { diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.ts b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.ts index 512fc8dd8e91c..f10f166232a2d 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.ts +++ b/packages/@aws-cdk/aws-apigateway/test/integ.spec-restapi.ts @@ -1,6 +1,7 @@ import * as path from 'path'; import * as lambda from '@aws-cdk/aws-lambda'; import * as cdk from '@aws-cdk/core'; +import { Size } from '@aws-cdk/core'; import { IntegTest } from '@aws-cdk/integ-tests'; import * as apigateway from '../lib'; @@ -11,6 +12,7 @@ class Test extends cdk.Stack { const api = new apigateway.SpecRestApi(this, 'my-api', { apiDefinition: apigateway.ApiDefinition.fromAsset(path.join(__dirname, 'sample-definition.yaml')), disableExecuteApiEndpoint: true, + minCompressionSize: Size.bytes(1024), retainDeployments: true, cloudWatchRole: true, deployOptions: { diff --git a/packages/@aws-cdk/aws-apigateway/test/restapi.test.ts b/packages/@aws-cdk/aws-apigateway/test/restapi.test.ts index 0156bd2cb4821..205686f7a0c5b 100644 --- a/packages/@aws-cdk/aws-apigateway/test/restapi.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/restapi.test.ts @@ -1,7 +1,7 @@ import { Template } from '@aws-cdk/assertions'; import { GatewayVpcEndpoint } from '@aws-cdk/aws-ec2'; import { testDeprecated } from '@aws-cdk/cdk-build-tools'; -import { App, CfnElement, CfnResource, Lazy, Stack } from '@aws-cdk/core'; +import { App, CfnElement, CfnResource, Lazy, Size, Stack } from '@aws-cdk/core'; import * as apigw from '../lib'; describe('restapi', () => { @@ -868,163 +868,252 @@ describe('restapi', () => { expect(method.api).toBeDefined(); }); - describe('Import', () => { - test('fromRestApiId()', () => { - // GIVEN - const stack = new Stack(); + test('RestApi minCompressionSize', () => { + // GIVEN + const app = new App({ + context: { + '@aws-cdk/aws-apigateway:disableCloudWatchRole': true, + }, + }); - // WHEN - const imported = apigw.RestApi.fromRestApiId(stack, 'imported-api', 'api-rxt4498f'); + const stack = new Stack(app); + const api = new apigw.RestApi(stack, 'RestApi', { + minCompressionSize: Size.bytes(1024), + }); - // THEN - expect(stack.resolve(imported.restApiId)).toEqual('api-rxt4498f'); - expect(imported.restApiName).toEqual('imported-api'); + // WHEN + api.root.addMethod('GET'); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', { + Name: 'RestApi', + MinimumCompressionSize: 1024, }); + }); - test('fromRestApiAttributes()', () => { - // GIVEN - const stack = new Stack(); + testDeprecated('RestApi minimumCompressionSize', () => { + // GIVEN + const app = new App({ + context: { + '@aws-cdk/aws-apigateway:disableCloudWatchRole': true, + }, + }); - // WHEN - const imported = apigw.RestApi.fromRestApiAttributes(stack, 'imported-api', { - restApiId: 'test-restapi-id', - rootResourceId: 'test-root-resource-id', - }); - const resource = imported.root.addResource('pets'); - resource.addMethod('GET'); + const stack = new Stack(app); + const api = new apigw.RestApi(stack, 'RestApi', { + minimumCompressionSize: 1024, + }); - // THEN - Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { - PathPart: 'pets', - ParentId: stack.resolve(imported.restApiRootResourceId), - }); - Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { - HttpMethod: 'GET', - ResourceId: stack.resolve(resource.resourceId), - }); - expect(imported.restApiName).toEqual('imported-api'); - }); - - test('fromRestApiAttributes() with restApiName', () => { - // GIVEN - const stack = new Stack(); + // WHEN + api.root.addMethod('GET'); - // WHEN - const imported = apigw.RestApi.fromRestApiAttributes(stack, 'imported-api', { - restApiId: 'test-restapi-id', - rootResourceId: 'test-root-resource-id', - restApiName: 'test-restapi-name', - }); - const resource = imported.root.addResource('pets'); - resource.addMethod('GET'); + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', { + Name: 'RestApi', + MinimumCompressionSize: 1024, + }); + }); - // THEN - Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { - PathPart: 'pets', - ParentId: stack.resolve(imported.restApiRootResourceId), - }); - Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { - HttpMethod: 'GET', - ResourceId: stack.resolve(resource.resourceId), - }); - expect(imported.restApiName).toEqual('test-restapi-name'); + testDeprecated('throws error when both minimumCompressionSize and minCompressionSize are used', () => { + // GIVEN + const app = new App({ + context: { + '@aws-cdk/aws-apigateway:disableCloudWatchRole': true, + }, }); + + // WHEN + const stack = new Stack(app); + + // THEN + expect(() => new apigw.RestApi(stack, 'RestApi', { + minCompressionSize: Size.bytes(500), + minimumCompressionSize: 1024, + })).toThrow(/both properties minCompressionSize and minimumCompressionSize cannot be set at once./); }); +}); - describe('SpecRestApi', () => { - test('add Methods and Resources', () => { - // GIVEN - const stack = new Stack(); - const api = new apigw.SpecRestApi(stack, 'SpecRestApi', { - apiDefinition: apigw.ApiDefinition.fromInline({ foo: 'bar' }), - }); - // WHEN - const resource = api.root.addResource('pets'); - resource.addMethod('GET'); +describe('Import', () => { + test('fromRestApiId()', () => { + // GIVEN + const stack = new Stack(); - // THEN - Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { - PathPart: 'pets', - ParentId: stack.resolve(api.restApiRootResourceId), - }); - Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { - HttpMethod: 'GET', - ResourceId: stack.resolve(resource.resourceId), - }); + // WHEN + const imported = apigw.RestApi.fromRestApiId(stack, 'imported-api', 'api-rxt4498f'); + + // THEN + expect(stack.resolve(imported.restApiId)).toEqual('api-rxt4498f'); + expect(imported.restApiName).toEqual('imported-api'); + }); + + test('fromRestApiAttributes()', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const imported = apigw.RestApi.fromRestApiAttributes(stack, 'imported-api', { + restApiId: 'test-restapi-id', + rootResourceId: 'test-root-resource-id', }); + const resource = imported.root.addResource('pets'); + resource.addMethod('GET'); - test('"endpointTypes" can be used to specify endpoint configuration for SpecRestApi', () => { - // GIVEN - const stack = new Stack(); + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { + PathPart: 'pets', + ParentId: stack.resolve(imported.restApiRootResourceId), + }); + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { + HttpMethod: 'GET', + ResourceId: stack.resolve(resource.resourceId), + }); + expect(imported.restApiName).toEqual('imported-api'); + }); - // WHEN - const api = new apigw.SpecRestApi(stack, 'api', { - apiDefinition: apigw.ApiDefinition.fromInline({ foo: 'bar' }), - endpointTypes: [apigw.EndpointType.EDGE, apigw.EndpointType.PRIVATE], - }); + test('fromRestApiAttributes() with restApiName', () => { + // GIVEN + const stack = new Stack(); - api.root.addMethod('GET'); + // WHEN + const imported = apigw.RestApi.fromRestApiAttributes(stack, 'imported-api', { + restApiId: 'test-restapi-id', + rootResourceId: 'test-root-resource-id', + restApiName: 'test-restapi-name', + }); + const resource = imported.root.addResource('pets'); + resource.addMethod('GET'); - // THEN - Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', { - EndpointConfiguration: { - Types: [ - 'EDGE', - 'PRIVATE', - ], - }, - }); + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { + PathPart: 'pets', + ParentId: stack.resolve(imported.restApiRootResourceId), }); + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { + HttpMethod: 'GET', + ResourceId: stack.resolve(resource.resourceId), + }); + expect(imported.restApiName).toEqual('test-restapi-name'); + }); +}); - testDeprecated('addApiKey is supported', () => { - // GIVEN - const stack = new Stack(); - const api = new apigw.SpecRestApi(stack, 'myapi', { - apiDefinition: apigw.ApiDefinition.fromInline({ foo: 'bar' }), - }); - api.root.addMethod('OPTIONS'); +describe('SpecRestApi', () => { + test('add Methods and Resources', () => { + // GIVEN + const stack = new Stack(); + const api = new apigw.SpecRestApi(stack, 'SpecRestApi', { + apiDefinition: apigw.ApiDefinition.fromInline({ foo: 'bar' }), + }); - // WHEN - api.addApiKey('myapikey', { - apiKeyName: 'myApiKey1', - value: '01234567890ABCDEFabcdef', - }); + // WHEN + const resource = api.root.addResource('pets'); + resource.addMethod('GET'); - // THEN - Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::ApiKey', { - Enabled: true, - Name: 'myApiKey1', - StageKeys: [ - { - RestApiId: { Ref: 'myapi162F20B8' }, - StageName: { Ref: 'myapiDeploymentStageprod329F21FF' }, - }, + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Resource', { + PathPart: 'pets', + ParentId: stack.resolve(api.restApiRootResourceId), + }); + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', { + HttpMethod: 'GET', + ResourceId: stack.resolve(resource.resourceId), + }); + }); + + test('"endpointTypes" can be used to specify endpoint configuration for SpecRestApi', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const api = new apigw.SpecRestApi(stack, 'api', { + apiDefinition: apigw.ApiDefinition.fromInline({ foo: 'bar' }), + endpointTypes: [apigw.EndpointType.EDGE, apigw.EndpointType.PRIVATE], + }); + + api.root.addMethod('GET'); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', { + EndpointConfiguration: { + Types: [ + 'EDGE', + 'PRIVATE', ], - Value: '01234567890ABCDEFabcdef', - }); + }, }); + }); - test('featureFlag @aws-cdk/aws-apigateway:disableCloudWatchRole CloudWatch role is not created created for API Gateway', () => { - // GIVEN - const app = new App({ - context: { - '@aws-cdk/aws-apigateway:disableCloudWatchRole': true, + testDeprecated('addApiKey is supported', () => { + // GIVEN + const stack = new Stack(); + const api = new apigw.SpecRestApi(stack, 'myapi', { + apiDefinition: apigw.ApiDefinition.fromInline({ foo: 'bar' }), + }); + api.root.addMethod('OPTIONS'); + + // WHEN + api.addApiKey('myapikey', { + apiKeyName: 'myApiKey1', + value: '01234567890ABCDEFabcdef', + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::ApiKey', { + Enabled: true, + Name: 'myApiKey1', + StageKeys: [ + { + RestApiId: { Ref: 'myapi162F20B8' }, + StageName: { Ref: 'myapiDeploymentStageprod329F21FF' }, }, - }); + ], + Value: '01234567890ABCDEFabcdef', + }); + }); - const stack = new Stack(app); - const api = new apigw.SpecRestApi(stack, 'SpecRestApi', { - apiDefinition: apigw.ApiDefinition.fromInline({ foo: 'bar' }), - }); + test('featureFlag @aws-cdk/aws-apigateway:disableCloudWatchRole CloudWatch role is not created created for API Gateway', () => { + // GIVEN + const app = new App({ + context: { + '@aws-cdk/aws-apigateway:disableCloudWatchRole': true, + }, + }); - // WHEN - const resource = api.root.addResource('pets'); - resource.addMethod('GET'); + const stack = new Stack(app); + const api = new apigw.SpecRestApi(stack, 'SpecRestApi', { + apiDefinition: apigw.ApiDefinition.fromInline({ foo: 'bar' }), + }); - // THEN - Template.fromStack(stack).resourceCountIs('AWS::IAM::Role', 0); - Template.fromStack(stack).resourceCountIs('AWS::ApiGateway::Account', 0); + // WHEN + const resource = api.root.addResource('pets'); + resource.addMethod('GET'); + + // THEN + Template.fromStack(stack).resourceCountIs('AWS::IAM::Role', 0); + Template.fromStack(stack).resourceCountIs('AWS::ApiGateway::Account', 0); + }); + + test('SpecRestApi minimumCompressionSize', () => { + // GIVEN + const app = new App({ + context: { + '@aws-cdk/aws-apigateway:disableCloudWatchRole': true, + }, + }); + + const stack = new Stack(app); + const api = new apigw.SpecRestApi(stack, 'SpecRestApi', { + apiDefinition: apigw.ApiDefinition.fromInline({ foo: 'bar' }), + minCompressionSize: Size.bytes(1024), + }); + + // WHEN + api.root.addMethod('GET'); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', { + Name: 'SpecRestApi', + MinimumCompressionSize: 1024, }); });