Review the API Gateway compression threshold

Use a valid byte threshold when compression is needed.

Description

CloudFormation accepts MinimumCompressionSize values from 0 to 10485760 bytes. Omit the property to disable REST API compression.

Potential impact

An out-of-range value can prevent deployment. A low threshold can add processing time for small responses.

Remediation

Choose a threshold and redeploy the API. Test a response at or above it from a backend that omits Content-Encoding. Send Accept-Encoding: gzip and check for Content-Encoding: gzip in the response. Use HTTPS for transport encryption.

Examples

-1 is invalid in CloudFormation. The example uses 0, which makes responses of any size eligible for compression.

Before

yaml
Resources:
  RestApi:
    Type: AWS::ApiGateway::RestApi
    Properties:
      Name: myApi
      MinimumCompressionSize: -1

After

yaml
Resources:
  RestApi:
    Type: AWS::ApiGateway::RestApi
    Properties:
      Name: myApi
      MinimumCompressionSize: 0

References