DEV Community

Ryszard Grodzicki
Ryszard Grodzicki

Posted on

Set up Content Encoding for AWS API Gateway in Terraform

Content Encoding in AWS Console

Recently, when looking through API Gateway settings I stumbled upon Content Encoding:
Image description
I was curious and thought that I surely want it enabled (and that it should be enabled by default...). So I set it up, tested, was glad with the results, so wanted to include it in my terraform setup.

After searching the web for some time I was sure it's not possible to set it up. In none of the resources related to the API Gateway, stage or deployment, was any parameter related to encoding.

Setup in Terraform

I must've dig really deep into aws terraform provider commit history to find out that they've hidden this parameter under aws_api_gateway_rest_api resource and named it minimum_compression_size !?

So, when this parameter is defined, it means the Content Encoding is turned on and sets what in AWS Console was called Minimum body size required for compression.

resource "aws_api_gateway_rest_api" "this" {
  name        = "the-best-api"
  description = "Api gateway for ${var.environment} environment"
  minimum_compression_size = 4096
}
Enter fullscreen mode Exit fullscreen mode

Hope this helps you and will save you some time searching through the web. 👍

Give this post a heart if you like it!

Top comments (1)

Collapse
 
sjclemmy profile image
Steve Clements

Thanks for this - was just looking for this setting by searching "content"!