【发布时间】:2017-01-18 16:18:06
【问题描述】:
我在 lambda 函数内有以下代码,这是 Amazon 回显技能:
"AMAZON.HelpIntent": function (intent, session, response) {
var speechOutput ="Start";
// Try S3
var s3 = new AWS.S3({httpOptions: { timeout: 2000 }});
var params = {
Bucket: 'bucket',
Key: 'file',
};
s3.getObject(params, function (err, data) {
if (err) {
// console.log(err, err.stack);
speechOutput += "inside error";
speechOutput += "Did not get it!" + err + ":===:" + err.stack;
}
else {
speechOutput += "inside success";
// console.log(data);
speechOutput += "Got it! :" + data.Body.toString('ascii');
}
});
speechOutput += " End. ";
var repromptText = "Help reprompt.";
response.ask(speechOutput, repromptText);
},
看起来很简单......但是,当技能被执行时,响应是这样的:
{
"version": "1.0",
"response": {
"outputSpeech": {
"type": "PlainText",
"text": "Start End. "
},
"shouldEndSession": false,
"reprompt": {
"outputSpeech": {
"type": "PlainText",
"text": "Help reprompt."
}
}
},
"sessionAttributes": {}
}
换句话说,s3.getObject 不会抛出任何错误,也不会运行。
lamda 函数具有“lambda_basic_execution”角色,在 IAM 中定义为对 S3 具有完全访问权限:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": "*"
}
]
}
在 S3 内部,有一个存储桶(名为“bucket”)和文件(名为“file”)。文件可从 CLI 和 Web 访问。存储桶和文件的权限设置为“所有人”。
请帮忙。
【问题讨论】:
标签: node.js amazon-web-services amazon-s3 lambda