Steven Best
Steven Best

Reputation: 13

AWS Lambda 'Process exited before completing request'

I've been trying to learn to make skills for Amazon Echo. I successfully made a super simple one that literally just responds with hello.

For a second attempt, to try and pin down what I've learned, I wanted to be a bit more adventurous, and make have Alexa provide a random GoT quote from an Array. I'm fairly new to coding in general, mostly been working on web stuff. I have tried searching for quite a while through different means and can't find anything that has helped.

When testing in Lambda I receive an error "Process exited before completing request" in Log Output I can also see "Alexa is not defined at exports.handler", I've been banging my head against this for a while so really hoping someone can help. Sorry for the long windedness of this..

Below is my code:

"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();
};

Upvotes: 0

Views: 1066

Answers (1)

jontro
jontro

Reputation: 10628

Change

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

to

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

Also before this change you were overwriting the lowercase alexa variable. I would recommend using a linter for your javascript code as this would catch issues like using undefined variables before use.

Upvotes: 2

Related Questions