Skip to content

Instantly share code, notes, and snippets.

@tguar
Last active July 31, 2016 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tguar/9df3b000ed58be8a2c95c974fa2b44d4 to your computer and use it in GitHub Desktop.
Save tguar/9df3b000ed58be8a2c95c974fa2b44d4 to your computer and use it in GitHub Desktop.

Creating an Amazon Echo Skill with Flask-Ask

Motivation:

I just bought an Amazon Echo because it looked cool and I just recently injured my knee so I had a lot of time to sit and think. I knew I wanted to develop on it even though I had no previous experience or really any knowledge of Alexa's capabilities. The opportunity for a free t-shirt offer from Amazon only strengenthed my resolve.

Learning:

I looked at Amazon's examples and tried them out, creating an Alexa skill and a Lambda function, then connecting the two. First in Node.js then in Python, because I have never worked in Python before. So then I started to create my own. I was making a "Today in History" skill when I realized that testing the project when creating the Lambda function inline was taking more time then I wanted, which was saying a lot when the only "exercise" I could do was walk around. This is how I stumbled upon John Wheeler's Flask-Ask. When paired with ngrok, Flask-Ask allowed me to test my code locally, saving me time and frustration. Here is John's 5 minute quick-start. This was a great set-up unti I had to go...

Back to Amazon:

I had been in the zone, everything was working great. I was churning out functionality left and right. But every project has that oh crap moment (sometimes more) and this was mine. I could not get my uploaded project to work. Even following the AWS tutorial was getting me nowhere. This is when I reached out to John. He said he was working on it too and told me that Zappa would be necessary for this to work. With a modified version of Flask-Ask John provided that has pyopenssl removed, I was able "serve" the code via AWS instead of locally.

The following are the steps I took to find success:
Note: You will need to create an IAM user with Administrative Access, as Amazon does not allow root login.

In Terminal:

mkdir project
cd project
git clone https://github.com/johnwheeler/flask-ask/
virtualenv venv
. venv/bin/activate
pip install -U pip setuptools
pip install aniso8601 pyyaml flask zappa unirest arrow
touch myskill.py
An example: myskill.py
touch zappa_settings.
An example:

{
    "dev": {
       "s3_bucket": "your_s3_bucket_name",
       "app_function": "myskill.app"
    }
}

zappa deploy dev
This will return an important link Something like https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev

In a Browser

Create a new Alexa Skill.
Add the interaction model.
Note: If you are looking to recreate my skill, note that I have two custom slots types: {{Stations}} and {{Routes}}.
When you get to the Configuration tab, the link that zappa deploy dev returned goes in the endpoint box. Make sure to check the radio button HTTPS and not ARN. This is confusing because it does have a Lambda ARN but Zappa best explains it here.

To explain what's going on, when you call 'deploy', Zappa will automatically package up your application and local virtual environment into a Lambda-compatible archive, replace any dependencies with versions precompiled for Lambda, set up the function handler and necessary WSGI Middleware, upload the archive to S3, register it as a new Lambda function, create a new API Gateway resource, create WSGI-compatible routes for it, link it to the new Lambda function, and finally delete the archive from your S3 bucket. Handy!

After you click next, select the radio button for My development endpoint is a subdomain of a domain that has a wildcard certificate from a certificate authority in the SSL Certificate tab.

There you go, you should be able to test your skill correctly!
Finally, there a few more things I will add in this write-up later on. In the meantime, enjoy the videos below.

Amazon Echo Skill Demonstration for Gainesville, FL Bus System Part I Demo 1
Amazon Echo Skill Demonstration for Gainesville, FL Bus System Part II
Demo 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment