Gzip response encoding?

It is possible to gzip responses but there are a couple of limitations.
My Java framework JRestless supports it - partially i.e. for binary responses. Here’s an example for it: https://github.com/bbilger/jrestless-examples/tree/master/aws/gateway/aws-gateway-binary

Since you are probably not interested in a solution for Java, let me try to explain how it works in general (for lambda proxy integration):
At the moment gzipping responses in APIGW makes - IMO - sense for binary responses, only.

This is how binary responses work:

  1. In APIGW binary responses are supported partially, only. This means you need to
    1.1. define so called binary media types
    1.2. return the binary data in the body base64 encoded from your lambda function
    1.3. flag the response with “isBase64Encoded”: true
  2. Binary media types - as far as I know - can still not be defined in serverless, so you have to define them in APIGW manually. (see the screenshots in the example mentioned)
  3. All requests to get a binary response from an endpoint must include an “Accept” header with one of the binary media types as value. If you don’t, the response body will be a base64 encoded string

So once you managed to setup binary responses, all you need to do, is to gzip your binary data before you base64 encode it and send an additional response header “Content-Encoding: gzip” if you receive a request header “Accept-Encoding: gzip”.

It would be great if APIGW would support it out of the box and there’s a thread in the forum https://forums.aws.amazon.com/thread.jspa?threadID=192948&tstart=0