我正在尝试通过Lambda从s3存储桶读取数据,并且该文件是Excel文件(.xlsx) 但是当我打印流时它是空的。
const xlsx = require('xlsx');
const AWS = require('aws-sdk');
var ss = new AWS.S3();
exports.handler = async (event) => {
var file = ss.getObject({ Bucket: 'kapoorbck', Key: 'testdata.xlsx' }).createReadStream();
//console.log(file);
var buffers = [];
file.on('data', (data) => {
buffers.push(data);
});
console.log(buffers);
file.on('end', function () {
var buffer = Buffer.concat(buffers);
var workbook = xlsx.read(buffer);
//var sheet_name_list = workbook.SheetNames;
console.log(workbook);
});
return{
statusCode :200,
body : "Success"
}
}
答案 0 :(得分:0)
除了两件事之外,我没有发现核心逻辑有什么错
console.log(buffers);
。从流中读取它是异步操作,因此console.log需要位于data
事件监听器或end
事件监听器中。希望有帮助。