【发布时间】:2019-12-25 19:07:11
【问题描述】:
以下代码不返回 amazon s3 内容,它在控制台数据值时起作用。 我尝试在函数外声明变量并尝试从函数返回,但不起作用
const getMeridianToken1 = () =>{
s3 = new aws.S3();
// Create the parameters for calling listObjects
var bucketParams = {
Bucket: 'bucket-name',
Key: 'access_token.json'
};
// Call S3 to obtain a list of the objects in the bucket
s3.getObject(bucketParams, function(err, data) {
if (!err) {
var result = JSON.parse(data.Body.toString());
console.log("working here---",result.access_token);
return result.access_token; //this is not returning
}
});
//return JSON.parse(data.Body.toString()); //if hard code here it works, if i return s3 conteent the data variable not available here
}
console.log("not working",getMeridianToken1);
【问题讨论】:
标签: javascript node.js amazon-s3 graphql