我有一个 lambda 函数,我从外部 api 获取大约 2.5 MB 大小的缓冲区,但是当我在 JSON 对象中返回相同的缓冲区时,它变得超过 7.5 MB,这大于 lambda 响应大小(6MB)限制,我不确定它是如何发生的。这是我的代码
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
};