Node.js Alexa Görev Sorunu
Şu anda AWS Lambda aracılığıyla bir Node.js Alexa Görevini kodluyorum ve OpenWeather API'den bilgi alan ve bunu adlı bir değişkene ayrıştıran bir işlevi kodlamaya çalışıyorum weather. İlgili kod aşağıdaki gibidir:
var request = require('request');
var weather = "";
function isBadWeather(location) {
var endpoint = "http://api.openweathermap.org/data/2.5/weather?q=" + location + "&APPID=205283d9c9211b776d3580d5de5d6338";
var body = "";
request(endpoint, function (error, response, body) {
if (!error && response.statusCode == 200) {
body = JSON.parse(body);
weather = body.weather[0].id;
}
});
}
function testWeather()
{
setTimeout(function() {
if (weather >= 200 && weather < 800)
weather = true;
else
weather = false;
console.log(weather);
generateResponse(buildSpeechletResponse(weather, true), {});
}, 500);
}
Bu pasajı Cloud9 ve diğer IDE'lerde sayısız kez çalıştırdım ve kusursuz çalışıyor gibi görünüyor. Ancak, onu bir pakete sıkıştırıp AWS Lambda'ya yüklediğimde aşağıdaki hatayı alıyorum:
{
"errorMessage": "Cannot find module '/var/task/index'",
"errorType": "Error",
"stackTrace": [
"Function.Module._load (module.js:276:25)",
"Module.require (module.js:353:17)",
"require (internal/module.js:12:17)"
]
}
Sayısız makaleyi inceledim ve bu kodu çalıştırması gereken modül-js, istek ve diğer birçok Node modülü yükledim, ancak hiçbir şey bu sorunu çözecek gibi görünmüyor. İşte rehberim, her ihtimale karşı:
- planyr.zip
- index.js
- node_modules
- package.json
Sorunun ne olabileceğini bilen var mı? Şimdiden çok teşekkür ederim.


START RequestId: 46c71292-debf-11e6-a013-1be2c415a9c1 Version: $LATEST Unable to import module 'index': Error at Function.Module._resolveFilename (module.js:325:15) at Function.Module._load (module.js:276:25) at Module.require (module.js:353:17) at require (internal/module.js:12:17) END RequestId: 46c71292-debf-11e6-a013-1be2c415a9c1 REPORT RequestId: 46c71292-debf-11e6-a013-1be2c415a9c1 Duration: 55.76 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 16 MB