Debugging with Dashbird: API Gateway Encoding not Enabled
Tags: aws, serverless, devops
Published: 2021-03-08 12:57:05

When using services created by other people, it's often neither obvious what they mean, let alone **how to fix them**. One of these [error messages](https://dashbird.io/event-library/) you might see when using [Amazon API Gateway](https://dashbird.io/knowledge-base/api-gateway/what-is-aws-api-gateway/) is "**encoding not enabled**".

The first question here is, **what kind of encoding does this error message refer to**? The first thought might go into the video or audio encoding direction and lead to a dead-end since you probably didn't send any audio or video files. The error message is confusing because it **aims to compress your response payload**.

What does "API Gateway Encoding not Enabled" mean?
--------------------------------------------------

Content-encoding will be **disabled by default** when you create a new API. So it's very likely that you already have one or multiple APIs running that don't use this feature.

Depending on your API responses' size, **disabled content-encoding can lead to needlessly high traffic**. And outbound traffic from AWS can get expensive quickly.

How do you enable API Gateway content-encoding?
-----------------------------------------------

If you're using the API Gateway console, you can **simply enable content-encoding in your API settings**.

Be aware that there are two "Settings" menu-items. First, you need to **select your API**, and then you **select the settings of that API** and not the general settings of the API Gateway service at the bottom.

Below, you can see the highlighted "Settings" menu-item for a gateway called "Endpoint."

![API Gateway settings](https://lh3.googleusercontent.com/dPK9sVINvjuA6dItlrENd-MH_jb5bIwIbamq4wXJKIU7iRZVHORC-Rliww8rZms34Yt4jxG92W3JtmadoX5pBScqgE-mxd3Ru2yhkzK4hN-qxyVcdVyO5XPFCHcc7jIZrHlcoUmK)

API Gateway settings

If you're using the [AWS CLI](https://aws.amazon.com/cli/), the following command will update your API.

$ aws apigateway update-rest-api

    --rest-api-id <YOUR_API_ID>

    --patch-operations op=replace,path=/minimumCompressionSize,value=0

Replace <YOUR_API_ID> with the ID of the API you want to enable content-encoding for. If you choose a higher value than 0 for compression, all responses below that value **won't be compressed**.

With CloudFormation, you have to set the MinimumCompressionSize property of your AWS::ApiGateway::RestApi resource. 

Why should you disable content-encoding?
----------------------------------------

In most cases, content-encoding **doesn't pose any problems**. Compression algorithms are optimized these days, and **almost all HTTP clients can work with compressed response payloads**.

One reason to keep it disabled is **performance**. Compressing your responses doesn't come for free. Minimal responses or binary responses often **don't compress very well**, so you're better off sending them uncompressed and save latency by removing a compression step.

Another reason is **debugging**. If you need to scan some network frames with a tool like WireShark for some reason, **disabling content-encoding would give you more insights**.

The final reason is the support of **legacy browsers**. If you work in a slow-moving company, the chances are that you have some ancient versions of the Internet Explorer floating around. This can lead to problems with compressed responses, especially when their **content is an already zipped file**.

Summary
-------

Content-encoding is about the compression of your API responses, and you should consider enabling it to **save money on outgoing AWS traffic**.

If you have specific needs, like sending hard to compress binaries or only minimal response payloads, you can **opt-out to squeeze out the last few milliseconds of latency**.

You can also check if the content-encoding feature is enabled for API Gateway stages to compress API payloads with [Dashbird](https://dashbird.io/). The [Well-Architected Insights feature](https://dashbird.io/blog/introducing-well-architected-insights/) will give you a quick and easy understanding of how your current settings are impacting your whole system, what exactly is affected, and what to do about it:

![api gateway encoding not enabled
](https://dashbird.io/wp-content/uploads/2021/03/Screenshot-2021-03-08-at-11.51.21.png)

Dashbird's Well-Architected checks against API Gateway encoding

* * * * *

Further reading:

[Debugging with Dashbird: Malformed Lambda Proxy Response](https://dashbird.io/blog/malformed-lambda-proxy-response/)

[Building complex Well-Architected Infrastructures](https://dashbird.io/blog/building-complex-well-architected-serverless-architectures/)

[AWS Well-Architected Framework in Serverless: Security Pillar](https://dashbird.io/blog/well-architected-framework-security/)