mardi 8 septembre 2015

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(myJson, 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.




Aucun commentaire:

Enregistrer un commentaire