|
1 | 1 | import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
|
2 | 2 | import { IVpcEndpoint } from '@aws-cdk/aws-ec2';
|
3 | 3 | import * as iam from '@aws-cdk/aws-iam';
|
4 |
| -import { ArnFormat, CfnOutput, IResource as IResourceBase, Resource, Stack, Token, FeatureFlags, RemovalPolicy } from '@aws-cdk/core'; |
| 4 | +import { ArnFormat, CfnOutput, IResource as IResourceBase, Resource, Stack, Token, FeatureFlags, RemovalPolicy, Size } from '@aws-cdk/core'; |
5 | 5 | import { APIGATEWAY_DISABLE_CLOUDWATCH_ROLE } from '@aws-cdk/cx-api';
|
6 | 6 | import { Construct } from 'constructs';
|
7 | 7 | import { ApiDefinition } from './api-definition';
|
@@ -225,9 +225,22 @@ export interface RestApiProps extends RestApiOptions {
|
225 | 225 | * payload size.
|
226 | 226 | *
|
227 | 227 | * @default - Compression is disabled.
|
| 228 | + * @deprecated - superseded by `minCompressionSize` |
228 | 229 | */
|
229 | 230 | readonly minimumCompressionSize?: number;
|
230 | 231 |
|
| 232 | + /** |
| 233 | + * A Size(in bytes, kibibytes, mebibytes etc) that is used to enable compression (with non-negative |
| 234 | + * between 0 and 10485760 (10M) bytes, inclusive) or disable compression |
| 235 | + * (when undefined) on an API. When compression is enabled, compression or |
| 236 | + * decompression is not applied on the payload if the payload size is |
| 237 | + * smaller than this value. Setting it to zero allows compression for any |
| 238 | + * payload size. |
| 239 | + * |
| 240 | + * @default - Compression is disabled. |
| 241 | + */ |
| 242 | + readonly minCompressionSize?: Size; |
| 243 | + |
231 | 244 | /**
|
232 | 245 | * The ID of the API Gateway RestApi resource that you want to clone.
|
233 | 246 | *
|
@@ -261,6 +274,18 @@ export interface SpecRestApiProps extends RestApiBaseProps {
|
261 | 274 | * @see https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-import-api.html
|
262 | 275 | */
|
263 | 276 | readonly apiDefinition: ApiDefinition;
|
| 277 | + |
| 278 | + /** |
| 279 | + * A Size(in bytes, kibibytes, mebibytes etc) that is used to enable compression (with non-negative |
| 280 | + * between 0 and 10485760 (10M) bytes, inclusive) or disable compression |
| 281 | + * (when undefined) on an API. When compression is enabled, compression or |
| 282 | + * decompression is not applied on the payload if the payload size is |
| 283 | + * smaller than this value. Setting it to zero allows compression for any |
| 284 | + * payload size. |
| 285 | + * |
| 286 | + * @default - Compression is disabled. |
| 287 | + */ |
| 288 | + readonly minCompressionSize?: Size; |
264 | 289 | }
|
265 | 290 |
|
266 | 291 | /**
|
@@ -648,6 +673,7 @@ export class SpecRestApi extends RestApiBase {
|
648 | 673 | name: this.restApiName,
|
649 | 674 | policy: props.policy,
|
650 | 675 | failOnWarnings: props.failOnWarnings,
|
| 676 | + minimumCompressionSize: props.minCompressionSize?.toBytes(), |
651 | 677 | body: apiDefConfig.inlineDefinition ?? undefined,
|
652 | 678 | bodyS3Location: apiDefConfig.inlineDefinition ? undefined : apiDefConfig.s3Location,
|
653 | 679 | endpointConfiguration: this._configureEndpoints(props),
|
@@ -758,12 +784,16 @@ export class RestApi extends RestApiBase {
|
758 | 784 | constructor(scope: Construct, id: string, props: RestApiProps = { }) {
|
759 | 785 | super(scope, id, props);
|
760 | 786 |
|
| 787 | + if (props.minCompressionSize !== undefined && props.minimumCompressionSize !== undefined) { |
| 788 | + throw new Error('both properties minCompressionSize and minimumCompressionSize cannot be set at once.'); |
| 789 | + } |
| 790 | + |
761 | 791 | const resource = new CfnRestApi(this, 'Resource', {
|
762 | 792 | name: this.physicalName,
|
763 | 793 | description: props.description,
|
764 | 794 | policy: props.policy,
|
765 | 795 | failOnWarnings: props.failOnWarnings,
|
766 |
| - minimumCompressionSize: props.minimumCompressionSize, |
| 796 | + minimumCompressionSize: props.minCompressionSize?.toBytes() ?? props.minimumCompressionSize, |
767 | 797 | binaryMediaTypes: props.binaryMediaTypes,
|
768 | 798 | endpointConfiguration: this._configureEndpoints(props),
|
769 | 799 | apiKeySourceType: props.apiKeySourceType,
|
|
0 commit comments