我试图使用下面的代码解压缩base64解码的缓冲区对象,但回调函数没有被执行。谁能告诉我我在这里缺少什么
function (event, context) {
event.Records.forEach(function (record) {
// Kinesis data is base64 encoded so decode here
var payload = new Buffer(record.kinesis.data, 'base64');
zlib.gunzip(payload, function (err, data) {
console.log("new data2");
if (!err) {
console.log("new data3");
console.log(data);
}
else {
console.log("new data4");
console.log(err, err.stack);
}
});
});
context.done();
};
答案 0 :(得分:3)
将context.done()
调用移动到您的回调中,以便Lambda函数不会提前终止。像这样:
function (event, context) {
event.Records.forEach(function (record) {
// Kinesis data is base64 encoded so decode here
var payload = new Buffer(record.kinesis.data, 'base64');
zlib.gunzip(payload, function (err, data) {
console.log("new data2");
if (!err) {
console.log("new data3");
console.log(data);
}
else {
console.log("new data4");
console.log(err, err.stack);
}
context.done();
});
});
};