Reputation: 33
I am trying to fetch an object from a s3 bucket. However I don't get a response, but also no error logged in the console.
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);
});
}));
}
I call the function in following function:
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();
}
and get following log
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
Upvotes: 3
Views: 1380
Reputation: 12542
So, basically you are not waiting for the run function to complete.
Change it to
await run();
This will wait for the Promise
to resolve
Upvotes: 1