我正在尝试为 Amazon Echo 创建一项技能,该技能将从 AWS S3 调用 JSON 文件。当我从 s3 基本 get 函数调用代码时,它可以工作。亚马逊 Alexa 代码可以独立运行。
但是当我将它们一起调用时,函数会被跳过。因此,对于以下代码,控制台在之前和之后被调用s3.getObject()
。但是中间的被跳过了。我不懂为什么。
我还检查了是否调用了 s3,确实如此。
let aws = require('aws-sdk');
let s3 = new aws.S3({ apiVersion: '2006-03-01'});
function callS3() {
console.log('loading S3 function');
var myData = [];
const params = {
Bucket: 'cvo-echo',
Key: 'data.json'
};
console.log("trying to get s3");
s3.getObject(params, (err, data) => {
if (err) {
console.log('error in s3 get: \n' + err);
//const message = `Error getting object ${key} from bucket ${bucket}.
// Make sure they exist and your bucket is in same region as this function.
//console.log(message);
} else {
console.log('CONTENT TYPE: ', data.ContentType);
console.log('Data body: \n' + data.Body.toString());
myData = JSON.parse(data.Body.toString());
console.log('myData.length = ' + myData.length);
}
console.log('myData >> ' + myData);
});
console.log('finished callS3() func');
return myData;
}