alexa-js / alexa-app

A framework for Alexa (Amazon Echo) apps using Node.js
https://www.youtube.com/watch?v=pzM4jv7k7Rg
MIT License
1.03k stars 213 forks source link

Error: function response: Handler 'handle' missing on module '_apex_index' #87

Closed dblock closed 7 years ago

dblock commented 8 years ago

I am sure this is a noob problem (sorry if it is), code in https://github.com/dblock/elderfield. The code works locally just fine, including if I download it from Lambda and run locally, but once on Lambda I get this:

$ apex invoke artsy
   ⨯ Error: function response: Handler 'handle' missing on module '_apex_index'

It's something in my alexa-app, because if stub that code with an apex hello world example that works. Can't find logs or anything else that helps :(

Halp!

dblock commented 8 years ago

Found the problem, looks like module.exports = app; is causing this. What's the recommended way to combine alexa-app-server and lambda? I am trying to use alexa-app-server in development and use apex to deploy the function to lambda.

Can make it work with some ENV settings, but seems ugly.

if (process.env['LAMBDA_FUNCTION_NAME'] != null) {
    console.log("AWS lambda")
    exports.handle = app.lambda();
} else if (process.env['ENV'] == 'development') {
    console.log("Development Mode")
    module.exports = app;
} else {
    var fs = require('fs');
    fs.writeFileSync('schema.json', app.schema());
    fs.writeFileSync('utterances.txt', app.utterances());
    console.log('Schema and utterances exported!');
}
ajcrites commented 7 years ago

@dblock the module.exports = app will make a handler function available on the export automatically so you can do this in lambda as well. Your issue is probably that you're using handle instead of handler in your lambda function definition.

You can also do exports.handle = app.lambda() regardless of whether this is running in a lambda context or not.

dblock commented 7 years ago

@ajcrites Are you saying I can collapse my dev mode with lambda mode in https://github.com/artsy/elderfield/blob/master/functions/artsy/index.js#L123?

dblock commented 7 years ago

This needs more thorough README. I'm going to close this for now though.

thegregthomp commented 7 years ago

I've notice that deploying with Apex changes the handler to "index.handle" where all the sdk examples uses handler. For this you'll want to modify Apex's project.json and add "handler":"index.handler"

dblock commented 7 years ago

@thegregthomp Can you please PR any doc changes?

thegregthomp commented 7 years ago

@dblock for me this is kind of an edge case in that you'd need to be using Apex for lambda deployments. I'm not sure that's worthy of a note in the docs because I'm not sure how many people actually deploy this way. If you feel it's a lot of people, I can do that.

dblock commented 7 years ago

Not sure, your call. I think lots of people use Apex, we do - http://artsy.github.io/blog/2016/11/30/bringing-artsy-to-amazon-echo-alexa/

expertcoder commented 7 years ago

I was just in the AWS console a moment ago. I created a new lambda function via the console. In the function configuration tab, the handler was set to index.handle (NO r) by default. However the boilerplate code provided for the lambda function had exports.handler (WITH r). This was a brief source of confusion for me

dblock commented 7 years ago

If something can be better documented, please PR!