alexa / alexa-skills-kit-sdk-for-nodejs

The Alexa Skills Kit SDK for Node.js helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Apache License 2.0
3.12k stars 736 forks source link

How to use this SDK with ngrok or a local host #73

Closed nemr closed 7 years ago

nemr commented 7 years ago

hello , How can I use this npm with ngrok instead of using it with AWS lambda ? where ngrok tunnels the local host to a secure public ip HTTPS.

ghost commented 7 years ago

You could support local testing by creating an express wrapper around the handler function. If you had an index.js which the following code:

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

exports.handler = function(event, context, callback){
    var alexa = Alexa.handler(event, context);
};

You could then create a file called local.js which creates an express app that calls the handler function and returns the result.

I did something like this a few weeks ago to facilitate local testing for a skill but the solution is not ideal because the Lambda Context object needs to be mocked (it's passed in as a parameter to the Alexa handler function).

With a bit more work, and some changes to the SDK, we could easily facilitate this. In the meantime, the work-around i described above would work.

ericblade commented 7 years ago

Potentially relevant https://github.com/alexa-js/alexa-app-server/issues/13

ghost commented 7 years ago

Running a test on localhost through TLS to an HTTPS connection over open web poses security risks. The local web server that ngrock is running will not contain a key/certificate pair, which is required for transport layer security (TLS) connection to an authenticated server. You can still connect, using the insecure parameter with the curl command, but you will not be using a hypertext transfer protocol with an encrypted connection, opening multiple vectors to the attack surface of your computer. Since you're planning on tunneling to an HTTPS site, I'm going to assume that's where your service for your actions are hosted, and you've configured them to respond properly once you make the request to the service.

If it were me, and you have your service hosted on a server that supports TCP tunneling, (and you don't have the auth credentials for full TLS) I would make sure that the server is accepting incoming connections on port 22 from the public IP address of your computer, and test invoking my actions through the SSH tunnel. I have no idea if a TCP tunnel would even work, it's just speculative opinion after reading through some documentation. You'd have to test that on your own.

As stated above, the Alexa Skills SDK and AWS Lambda are a perfect architecture match. It would be much easier, at this current state in the development process, to engineer your cloud services for an AWS Lambda. Good luck.

Edit: Spelling

eljefedelrodeodeljefe commented 7 years ago

I think this should be re-opened, since at least @bclement-amazon proceedings could be documented. Following the Alexa docs, choosing https over Lambda basically get you stuck here.

eljefedelrodeodeljefe commented 7 years ago

To be precise: the issue should not be around the tunnel, but local development or https routing to wrap Lambda event and context, since this is what his hindering users.

eljefedelrodeodeljefe commented 7 years ago

Fore reference https://stackoverflow.com/questions/44391242/how-to-run-alexa-skill-with-the-alexa-sdk-on-own-server-with-node-js-without-lam

mlopezr commented 6 years ago

Here's a repo showing how to create the Express wrapper around a skill to run it locally: https://github.com/Glogo/alexa-skill-sample-nodejs-express

dly9014 commented 6 years ago

I posted an approach to doing this up at the SO question noted above