AWS 拉姆达 'Process exited before completing request'

AWS Lambda 'Process exited before completing request'

我一直在努力学习为 Amazon Echo 制作技能。我成功地做了一个超级简单的,字面上只是用你好来回应。

第二次尝试,为了尝试确定我所学的内容,我想更大胆一点,让 Alexa 从数组中提供随机的 GoT 引述。一般来说,我对编码还很陌生,主要从事网络方面的工作。我已经尝试通过不同的方式搜索了很长一段时间,但找不到任何有用的东西。

在 Lambda 中测试时,我在日志输出中收到错误 "Process exited before completing request" 我还可以看到 "Alexa is not defined at exports.handler",我已经为此苦苦思索了一段时间,所以真的希望有人能提供帮助。抱歉啰啰嗦嗦..

下面是我的代码:

"use strict";

var alexa = require('alexa-sdk');

// QUOTES ARRAY
var quotes = [
        'A mind needs books as a sword needs a whetstone, if it is to keep its edge',
        'Never forget what you are, for surely the world will not',
        'I wont be knitting by the fire while I have men fight for me'
    ];


// HANDLERS
var handlers = {
    getThatQuote: function() {
        var quoteIndex = Math.floor(Math.random() * quotes.length);
        var randomQuote = quotes[quoteIndex];
        return randomQuote;
    },

    LaunchRequest: function() {
        this.emit(":tell", "Welcome to Game of Quotes");
    },
    QuoteGet: function() {
        this.emit(":tell", "Here is your quote" + this.getThatQuote());
    },
};

exports.handler = function (event, context) {
    const alexa = Alexa.handler(event, context);
    alexa.registerHandlers(handlers);
    alexa.execute();
};

改变

var alexa = require('alexa-sdk');

var Alexa = require('alexa-sdk');

此外,在此更改之前,您还覆盖了小写的 alexa 变量。我建议为您的 javascript 代码使用 linter,因为这会在使用前捕获诸如使用未定义变量之类的问题。