How to Test Alexa Locally

Muneeb Ahmad
2 min readMar 10, 2018

If you recently started developing an Alexa skill, you may be wondering how to test locally on your computer. Deploying to a lambda function every time can quickly become frustrating. This tutorial will help you test locally but to follow this tutorial you will need to have a functioning Alexa node.js skill.

To get the JSON object that is POSTed to the server, add the following line at the beginning of all of your IntentHandler functions.

console.log(“THIS.EVENT = “ + JSON.stringify(this.event));

Now deploy this to AWS Lambda (last time before you can start testing locally) and trigger an intent by speaking to Alexa. Look at the logs and you will be able to see the JSON object. It will have fields like the request, context, and session. Copy this JSON object and paste it into a new file called event.json in the directory of your project. You will need it later.

Since the alexa-sdk doesn’t allow for local testing, you will need to setup a lambda function locally. This is made easy by a package called lambda-local that you can download via npm. To install the package, go to the directory of your project and run:

npm install -g lambda-local

You’re all set to start testing locally!

Assuming all your code is in index.js, you will be able to run the following command and see a response:

lambda-local -l index.js -h handler -e event.json

If this works, you can now begin testing using your favorite debugger and put breakpoints and step through the logic. My favorite debugger for node.js is Visual Studio Code so I will walk through the steps to set up local testing for VS Code.

Open your project in VS Code and on the top, click on Debug -> Add Configuration. It will create a launch.json file for you and ask you what type of configuration you need. Choose {} Node.js: Launch Program. Now all you need to do is replicate the command line information to a format that VS Code understands. Below is what your launch.json should look like:

Congratulations! You can now set breakpoints anywhere in your code and step through the code every time you run your debugger. To test different intents, you can simply change the “request type” and “slots” in your event.json.

--

--

Muneeb Ahmad

Software Engineer at Thanx, an SF-based startup enabling deeper data-driven relationships between merchants and their best customers