Support New AWS APIGW Binary Responses #2797

jthomerson opened this Issue Nov 25, 2016 · 5 comments


None yet

5 participants


This is a Feature Proposal


Previously, AWS API Gateway did not support binary responses, making it impossible to return images from your serverless API. Now they do (see We need to be able to configure HTTP endpoints/events in serverless to use this new functionality.

@pmuens pmuens added the kind/feature label Nov 26, 2016

Does it mean we will be able to gzip response?


My team is eagerly anticipating this feature in Serverless. We have an image resizing service that currently needs to proxy responses through a traditional server to return images... 😫

Does anybody know of a workaround we could use until this is added to Serverless?

adambiggs commented Dec 17, 2016 edited

@vladgolubev our image resizing service resizes the images on-demand based on query string params. The lambda first checks if the requested image size already exists on S3. If it does, it returns the existing image, and if not it generates it, stores it on S3 and then returns it. So direct S3 links won't work for us.

Our current workaround is to run a simple Node.js reverse proxy that calls the Lambda image resize service, gets the direct S3 link, and then returns the binary response to the client...

But this is a temporary solution. When Serverless adds binary response support (or if we can find a workaround, like making changes directly in AWS after deploying with Serverless) we can get rid of the reverse proxy without changing any previously generated image URLs.

bbilger commented Dec 21, 2016 edited

Note: there's some thread in the forum about this:
The current issue - as far as I know - is that the binaryMediaTypes cannot be set in CloudFormation.
So your only option right now is to configure them manually (if I remember correctly it survives a re-deployment).
See here:
or here:
or in the blog post:

and sure you can also gzip: (not using serverless)

I would, however, not expect too much from it since
a) API Gateway has a size limit of 10MB (+ I guess you have to substract the base64 overhead from it)
b) only if a proper Accept header (for the response) or Content-Type header (for the request) i.e. one registered as binary media type is set, you'll get binary data, else you'll end up with base64 encoded content.
c) If I remember correctly there are issues with multiple accept headers like "Accept: image/png,image/gif"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment