我在亚马逊alexa中做了一个自定义技能,当在AWS中测试Node js代码作为LAMBDA函数时,它给出了以下错误:
{
"errorMessage": "Cannot find module '/var/task/index'",
"errorType": "Error",
"stackTrace": [
"Function.Module._load (module.js:417:25)",
"Module.require (module.js:497:17)",
"require (internal/module.js:20:19)"
]
}
以下是代码,它连接到firebase并更新其内容
const firebase = require('firebase');
exports.handler = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false; //<---Important
var config = {
apiKey: 'AIzaSyBQJasmuj2yzlkuXFwJ5-wL2kt0UMQ2V18',
authDomain: 'deftdev-a2416.firebaseapp.com',
databaseURL: 'https://deftdev-a2416.firebaseio.com',
storageBucket: 'deftdev-a2416.appspot.com'
};
//firebase.initializeApp(firebaseConfig);
//const db = firebase.database();
if(firebase.apps.length == 0) { // <---Important!!! In lambda, it will cause double initialization.
firebase.initializeApp(config);
}
firebase.database().ref('rooms/' +'HPOQhC9smxUxSGhM1XlBtweiNDE3/'+'roomdetails/01/1/appliance/0/'+).update({
toggle:1
});
};