我正在尝试从 s3 存储桶中获取对象。但是我没有得到响应,而且控制台中也没有错误记录。
function test(filename) {
return new Promise((resolve => {
var params = {
Bucket: bucket,
Key: "pptSource/"+filename
};
s3.getObject(params, function(err, data) {
// Handle any error and exit
if (err) {
console.log(err);
}
resolve(data.Body);
});
}));
}
我在下面的函数中调用函数:
exports.handler = async (event) => {
function test(filename) { .. }
async function run() {
var sourceFile = "XX_company_presentation_2019_v1~1-2.pptx";
var filename = sourceFile;
var pptSource = await test(filename);
console.log(pptSource);
}
run();
}
并获取后续日志
END RequestId: 078fcfaf-949d-4231-9bcb-a35d40ffd3a3
REPORT RequestId: 078fcfaf-949d-4231-9bcb-a35d40ffd3a3 Duration: 34.78 ms Billed Duration: 100 ms Memory Size: 3008 MB Max Memory Used: 106 MB
最佳答案
所以,基本上您不需要等待运行函数完成。
改成
await run();
这将等待 Promise
解决
关于node.js - S3 GetObject 不返回响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57134621/