1
你好,如何创建和读取fs.writeFile .txt文件到AWS LAMBDA
是否有人知道我可以写一个.txt到AWS LAMBDA?我正在使用Node.js,Alexa Skills Kit和Lambda。
我的代码:
var fs = require('fs');
const handlers = {
'SetOrderIntent': function() {
if (this.event.request.intent) {
var test = this.event.request.intent.slots.Items.value;
fs.writeFile('/tmp/log.txt', test, function (err) {
if (err) throw err;
});
this.emit(':ask', 'This is your item: ' + test, "Test");
}
},
'RetrieveOrderIntent': function() {
if (this.event.request.intent) {
fs.readFile('/tmp/log.txt', function (err, content) {
if (err) return callback(err)
callback(null, content)
})
this.emit(':ask', content);
}
},
}
你会推荐我使用S3还是使用session.Attributes? – Mae
我认为这取决于你的数据的大小,但对我来说,它看起来像它只有一个字符串的权利?比你应该尝试session.Attributes。 另外,您在'RetrieveOrderIntent'中发出同步。这意味着在readFile实际在回调中完成之前,您的emit会被触发。你应该在readFile回调中移动this.emit。 ''callback'从哪里来? – driedel
@Mae是否有效? – driedel