How to deploy Alexa Skill Code to AWS Lambda using Zappa

SatheeshAlexaLeave a Comment

If you are a developer trying to build something, it is always good to build it on the desktop, try it out and then once you are ready, then upload to the server. What we have done is used ngrock and flask_ask to build a flask app and run it locally. Now the server part comes in as we want to run it using AWS Lambda. Zappa is a great option to package and then upload the same to AWS Lambda. All of the below is executed on a Mac using Terminal. You

Step 1 : Have your Alexa Skill Code, which for a python file, in a folder. The reason is that we will create a virtual environment and then get dependencies gathered there and upload the same to AWS. One tip, avoid spaces in the folder name, sometimes AWS will give you errors as the spaces are not picked up well.

Step 2 :  Execute the below command to have own environment. If you have Anaconda installed then please install the virtualenv package using Anaconda. i.e

conda install virtualenv

If you don’t have Anaconda installed please do

pip install virtualenv

Once the virtualenv package is installed we can start the process at the folder where the files are stored. If you are for example having the files at root/Alexa/test then please go to that folder in your command prompt and then start the below process

virtualenv venv

You should get confirmation like below.

Step 3 : Now Activate the environment you have just created so that you can get all the dependencies setup in that environment. Once you enter the below command, you would see that you are in that environment that is indicated by (venv) in front of your command prompt in terminal.

source venv/bin/activate

Step 4 : You need to install Flask Zappa and related stuff using the below command to be able to send to AWS.

pip install flask flask_ask awscli zappa requests

Once you use the above command, you will see something like this, if everything is good.

Step 5 : Now you use the below command to initialize Zappa to upload your code to AWS Lambda

zappa init

Step 6 : You can continue to hit enter few times so that you can use standard settings and names, of course, you can change any of these, but for now, we will use the standard settings that are default. At the end you will get the zappa_settings.json created. Make sure you have the “us-east-1” region as aws region to avoid issues. Alexa is currently supported out of few regions only and us-east-1 is one of them. The standard settings look like below.

Step 7 :  Now you deploy the Alexa App using Zappa to dev using the below command.

zappa deploy dev

If you want to update, you would use zappa update dev

It takes couple of minutes for the package to be done and upload to AWS Lambda and depends on the network as well.  If everything goes well, you will get  ‘Deployment Complete’ in green and amazonaws.com URL that is the URL you will use in the Alexa Skill you will create in developer portal.

Step 8 : Test the Deployed URL .  You should copy the URL that is after the deployment complete message and paste it in browser. You would get message like below. If you get the below message, it means that the Alexa Skill Code has been uploaded to AWS Lambda.

Again please test if all is working fine by using

zappa tail dev

This will throw up any compiling errors that are there in your project. If not, it will look like below.

Step 9 : Now we use the above URL in Alexa Skill Creation in Developer Portal. https://developer.amazon.com/edw/home.html#/skills

Click on New Skill

Step 10 : Add the details of the Alexa Skill like below. You have to choose the language depending on how you have coded and hit Save.

Step 11 : After you hit save, you will get Next button on the bottom left and click on that to take you to interaction Model.

Step 12 : You should enter the Intents and Utterances in this section and hit save. The interaction model will be built using this.

Step 13 :  You will need to select HTTPS and put in the URL that was given at Zappa Deploy here as the default URL as shown below. You are now ready to save and hit next to select the SSL certificate.

Step 14 :  Now, select the SSL Certificate as wildcard certificate as below.

Step 15 : Now you are ready to test, if you hit next step after SSL. Click on the Go to Test Simulator or you can use the text boxes as well to manually enter and test.  I prefer the test simulator as it is good. Also, you can use the device, if you have it with you and directly test on it. Just say the app invocation name and start testing.

All checks need to show as green like for Skill information, Interaction model, Configuration, to make sure, it has all correct and built properly.

Step 16 : To test on simulator, you need to press and hold the mic icon on the top left and speak like start or open your app name.  If everything went well, your app should be opened and executed like below. You should be able to see the same in command form as well.

That’s it folks. Anything that I have missed ?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.