I have a lambda function,I get buffer from external api which is approximate 2.5 MB size but when I return same buffer in JSON object it becomes more than 7.5 MB, which is grater than lambda response size (6MB)limit,I am not sure how it is happening. Here is my code
module.exports.handler = (event, context, callback) => {
const buffer = getAnswer();
// This is approx 2.1 MB buffer size
console.log(`Buffer size ${buffer.byteLength}`);
const response = {
headers: {
'Content-Type': 'application/json',
},
isBase64Encoded: false,
statusCode: 200,
statusDescription: '200 OK',
body: JSON.stringify(buffer),
};
// Here size becomes more than 7.5 MB ,I am not sure how it happens
console.log('This becomes 7.5 MB size', Buffer.byteLength(JSON.stringify(response)), 'bytes');
context.succeed(response);// Gives error because it exceeds more than 6MB lambda response limit
};