错误与AWS LAMBDA

问题描述:

我一直在试图建立这个亚马逊技能thorugh拉姆达的工具,但我已经收到此错误:错误与AWS LAMBDA

{ 
    "errorMessage": "Cannot find module './AlexaSkill'", 
    "errorType": "Error", 
    "stackTrace": [ 
    "Function.Module._load (module.js:417:25)", 
    "Module.require (module.js:497:17)", 
    "require (internal/module.js:20:19)", 
    "Object.<anonymous> (/var/task/index.js:2:18)", 
    "Module._compile (module.js:570:32)", 
    "Object.Module._extensions..js (module.js:579:10)", 
    "Module.load (module.js:487:32)", 
    "tryModuleLoad (module.js:446:12)", 
    "Function.Module._load (module.js:438:3)" 
    ] 
} 

我看了所有可能的解决方案,甚至在荏苒正确的文件(我没有和它仍然无法正常工作)

这里的错误日志:

START RequestId: a3b6a9d5-204c-11e7-8778-8d44331f3381 Version: $LATEST 
Unable to import module 'index': Error 
    at Function.Module._resolveFilename (module.js:469:15) 
    at Function.Module._load (module.js:417:25) 
    at Module.require (module.js:497:17) 
    at require (internal/module.js:20:19) 
    at Object.<anonymous> (/var/task/index.js:2:18) 
    at Module._compile (module.js:570:32) 
    at Object.Module._extensions..js (module.js:579:10) 
    at Module.load (module.js:487:32) 
    at tryModuleLoad (module.js:446:12) 
    at Function.Module._load (module.js:438:3) 
END RequestId: a3b6a9d5-204c-11e7-8778-8d44331f3381 
REPORT RequestId: a3b6a9d5-204c-11e7-8778-8d44331f3381 Duration: 57.69 ms Billed Duration: 100 ms  Memory Size: 128 MB Max Memory Used: 23 MB 

这里是我的index.js的代码:

var request = require("request") 
    , AlexaSkill = require('./AlexaSkill') 
    , APP_ID  = 'amzn1.ask.skill.xxxxxx'; 

var error = function (err, response, body) { 
    console.log('ERROR [%s]', err); 
}; 

var getJsonFromUnity = function(color, shape, callback){ 

var command = "create " + color + " " + shape; 

if(color == "thank you"){ 
    callback("thank you"); 
} 
else{ 
var options = { method: 'GET', 
    url: 'https://xxxxxx.herokuapp.com/', 
    qs: { command: command }, 
    headers: 
    { 'postman-token': '230914f7-c478-4f13-32fd-e6593d8db4d1', 
    'cache-control': 'no-cache' } }; 

var error_log = ""; 

request(options, function (error, response, body) { 
    if (!error) { 
     error_log = color + " " + shape; 
    }else{ 
     error_log = "There was a mistake"; 
    } 
     callback(error_log); 
    }); 
} 
} 

var handleUnityRequest = function(intent, session, response){ 
    getJsonFromUnity(intent.slots.color.value,intent.slots.shape.value, function(data){ 
    if(data != "thank you"){ 
    var text = 'The ' + data + ' has been created'; 
    var reprompt = 'Which shape would you like?'; 
    response.ask(text, reprompt); 
    }else{ 
     response.tell("You're welcome"); 
    } 
    }); 
}; 

var Unity = function(){ 
    AlexaSkill.call(this, APP_ID); 
}; 

Unity.prototype = Object.create(AlexaSkill.prototype); 
Unity.prototype.constructor = Unity; 

Unity.prototype.eventHandlers.onSessionStarted = function(sessionStartedRequest, session){ 
    console.log("onSessionStarted requestId: " + sessionStartedRequest.requestId 
     + ", sessionId: " + session.sessionId); 
}; 

Unity.prototype.eventHandlers.onLaunch = function(launchRequest, session, response){ 
    // This is when they launch the skill but don't specify what they want. 

    var output = 'Welcome to Unity. Create any color shape by saying create and providing a color and a shape'; 

    var reprompt = 'Which shape would you like?'; 

    response.ask(output, reprompt); 

    console.log("onLaunch requestId: " + launchRequest.requestId 
     + ", sessionId: " + session.sessionId); 
}; 

Unity.prototype.intentHandlers = { 
    GetUnityIntent: function(intent, session, response){ 
    handleUnityRequest(intent, session, response); 
    }, 

    HelpIntent: function(intent, session, response){ 
    var speechOutput = 'Create a new colored shape. Which shape would you like?'; 
    response.ask(speechOutput); 
    } 
}; 

exports.handler = function(event, context) { 
    var skill = new Unity(); 
    skill.execute(event, context); 
}; 

谁能帮助我和针指向我一个解决方案吗?

该消息告诉您该文件AlexaSkill.js尚未在您的zip文件上传,或有可能,它是不是在指定的目录中。

检查.zip文件的您上传,以确保它包含的内容。还要确保它与index.js位于同一目录中。

由于您使用加载它“AlexaSkill =需要(‘./ AlexaSkill’)”,预计将在同一目录下。如果AlexaSkill.js实际上位于一个子目录中,例如命名为'src',那么您可以使用require('./ src/AlexaSkill')。

注意,指定的路径是相对于包含require()语句文件。

+0

这正是我的问题。我从一个更高的目录中压缩,所以我正在压缩文件夹而不是其中的内容 – lfender6445