DEV Community

loading...
Cover image for Debugging with Dashbird: API Gateway Encoding not Enabled
Dashbird

Debugging with Dashbird: API Gateway Encoding not Enabled

K
・3 min read

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 you might see when using Amazon 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

API Gateway settings

If you're using the AWS CLI, the following command will update your API.

$ aws apigateway update-rest-api

    --rest-api-id

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

Replace 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. The Well-Architected Insights feature 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<br>

Dashbird's Well-Architected checks against API Gateway encoding


Further reading:

Debugging with Dashbird: Malformed Lambda Proxy Response

Building complex Well-Architected Infrastructures

AWS Well-Architected Framework in Serverless: Security Pillar

Discussion (0)