2017-04-13 20 views
1

Ich habe versucht, dieses Amazon Geschick thorugh das Lambda-Werkzeug zu schaffen, aber ich habe diesen Fehler wurde immer:Fehler mit 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)" 
    ] 
} 

ich an allen möglichen Lösungen gesucht habe, auch die Zippen Datei korrekt

Hier ist das Fehlerprotokoll (was ich habe und es immer noch nicht funktioniert):

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 

Hier ist der Code meiner 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); 
}; 

Kann mir jemand helfen und mich auf eine Lösung hinweisen?

Antwort

2

Diese Nachricht teilt Ihnen mit, dass die Datei AlexaSkill.js nicht in Ihre ZIP-Datei hochgeladen wurde oder möglicherweise nicht in dem angegebenen Verzeichnis enthalten ist.

Überprüfen Sie den Inhalt der ZIP-Datei, die Sie hochgeladen haben, um sicherzustellen, dass sie enthalten ist. Stellen Sie außerdem sicher, dass es sich im selben Verzeichnis wie index.js befindet.

Da Sie es mit "AlexaSkill = require ('./ AlexaSkill')" laden, wird erwartet, dass es sich im selben Verzeichnis befindet. Wenn sich AlexaSkill.js tatsächlich in einem Unterverzeichnis befindet, beispielsweise mit dem Namen "src", würden Sie stattdessen require ('./ src/AlexaSkill') verwenden.

Beachten Sie, dass der angegebene Pfad relativ zu der Datei ist, die die require() -Anweisung enthält.

+0

das war genau mein Problem. Ich habe aus einem höheren Verzeichnis zippen, also habe ich den Ordner anstatt nur seinen Inhalt zippen – lfender6445