AWS Lambda'流程在完成请求之前退出'

时间:2017-10-12 23:20:43

标签: amazon-web-services aws-lambda alexa amazon-echo

我一直在努力学习为Amazon Echo制作技能。我成功地制作了一个非常简单的,只是用你好的回应。

为了第二次尝试,尝试确定我所学到的东西,我想要更冒险一点,并让Alexa从数组中提供一个随机的GoT引用。一般来说,我对编码很新,主要是从事网络工作。我试过通过不同的手段搜索了一段时间,找不到任何有帮助的东西。

在Lambda中进行测试时,我在日志输出中收到错误“在完成请求之前退出进程”,我也可以看到“Alexa未在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();
};

1 个答案:

答案 0 :(得分:2)

更改

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

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

在此更改之前,您还要覆盖小写alexa变量。我建议为你的javascript代码使用linter,因为这会在使用之前发现使用未定义变量等问题。