Review API Gateway response compression

Choose response compression and its minimum size to suit the API payloads.

Description

In Terraform, minimum_compression_size = -1 disables REST API compression. On a new API, you can omit the argument to leave compression off.

Potential impact

Compressing large responses can save bandwidth. Small ones can take longer to process or even grow after compression.

Remediation

To enable compression, choose a threshold from 0 to 10485760 bytes. Deploy the API, then compare response sizes and latency with Accept-Encoding: gzip. Use HTTPS for transport encryption.

Examples

Configure the REST API’s methods and integrations separately.

Before

hcl
resource "aws_api_gateway_rest_api" "example" {
  name = "regional-example"

  endpoint_configuration {
    types = ["REGIONAL"]
  }

  minimum_compression_size = -1
}

After

hcl
resource "aws_api_gateway_rest_api" "example" {
  name = "regional-example"

  endpoint_configuration {
    types = ["REGIONAL"]
  }

  minimum_compression_size = 0
}

The example changes -1 to 0, making responses of any size eligible for compression.

References