I'm trying to create an AWS Lambda accessed by API Gateway which returns gzipped json response.
This is my lambda code (typescript):
import { DB } from '@/DB/db';
import zlib from 'zlib';
import { promisify } from 'util';
export async function main(db: DB) {
const gzip = promisify(zlib.gzip);
console.info('procees of getTools tools started');
const result = await db.getToolsRepo().getTools();
const jsonString = JSON.stringify(result);
// Compress with gzip
const gzipCompressed = await gzip(Buffer.from(jsonString, 'utf-8'));
// Prepare the response
const response = {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
'Content-Encoding': 'gzip'
},
body: gzipCompressed.toString('base64'),
isBase64Encoded: true
};
return response;
}
How should I configure API Gateway ? I triend "content handling" - passthrough and "convert to binary" - both does not help - I get nested response instead of base64 binary data:
{"statusCode":200,"headers":{"Content-Type":"application/json","Content-Encoding":"gzip"},"body":"H4sIAA ...