Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gzipped response in AWS Lambda -> API Gateway

I can't seem to get a gzipped response from Lambda through the API Gateway. I'm gzipping my response in Lambda and setting the "Content-Encoding" header in API Gateway.

I'm not sure which part is the problem.

Here's the final return from Lambda to API Gateway:

zlib.gzip(myJsonString, function (err, buffer) {
    if ( err ) { return handleError(err, context) }

    return context.succeed(buffer.toString('binary'));
});

I've tried just passing the buffer, base64 encoding it, etc.

Making a GET request from Chrome: If I remove the Content-Encoding header from the gateway I get binary/base64/buffer array as a string response in the browser.

If I set the header, the GET request fails entirely with no response but testing in the AWS console returns the payload with quotes around it.

I don't know what's going on here but If Amazon actually wants people to use this thing we need to be able to compress our responses. Seems like it should just be a checkbox in API Gateway and then I could simply return a JSON string from Lambda and have it zipped up automatically.

like image 998
kjs3 Avatar asked Oct 31 '22 19:10

kjs3


1 Answers

As for Nov 17, 2016 - Binary Data Now Supported by API Gateway

Let me know if you figured that out!

like image 191
Vlad Holubiev Avatar answered Nov 15 '22 06:11

Vlad Holubiev