Skip to content

maheshpj/alexa-skill-flask-ask-zappa-seed

Repository files navigation

Alexa Skill with Flask-Ask Zappa seed project

Introduction

This project creates a microservice deployed on AWS API Gateway and Lambda and provides the API Gateway HTTPS Url in Alexa Developer portal.

Architecture

Alexa Skill Service Design

Tools and Technologies

  • Python 2.7
  • Flask-Ask: Flask-Ask is a Flask extension that makes building Alexa skills for the Amazon Echo.
  • cookiecutter-flask-ask: ready-to-roll Alexa Skill skeleton based on Flask-Ask
  • Zappa: Serverless framework for Lambda and API Gateway using python
  • Tox: virtualenv management and test command line tool using pytest
  • Sphinx: Documentation generator
  • AWSCli: AWS command line tool

Security

For better AWS security use custom AWS VPC and Security Group, add below configuration in your zappa_settings.json file

"vpc_config": {
    "SubnetIds": [ "subnet-12345678" ],
    "SecurityGroupIds": [ "sg-12345678" ]
}

Setup

It is recommended to run this project in a virtualenv. If virtualenvs are unfamiliar to you, this handy tutorial might be a good place to start.

Create Virtual Environment

  1. Install virtualenv: $ pip install virtualenv
  2. Create virtual environment names env: $ virtualenv env
  3. Activate env on Unix: $ source venv/bin/activate
  4. Activate env on Windows: $ env\Scripts\activate
  5. Install the required Python packages from root project folder: $ pip install -r requirements.txt --no-cache-dir

AWS Deployment

Create AWS User

  1. Create an IAM user named Zappa-Deploy in the AWS console
  2. Give AdministratorAccess policy for this user
  3. Once the user is created, its Access key ID and Secret access key are displayed, keep it safe

Configure IAM credentials locally

  1. Make sure you are in project root folder and virtual env is active
  2. Configure AWS: $ aws configure
  3. Follow the prompts to input your Access key ID and Secret access key.
  4. For Default region name, type: us-east-1.
  5. For Default output format: json.

This will install credentials and configuration in an .aws directory inside your home directory

Deploy the skill with Zappa

  1. zappa_settings.json file has all required configuration to deploy dev to AWS
  2. Very first time execute: $ zappa deploy dev
  3. Releasing code updates doesn't recreate the API gateways and is a faster. Such updates are handled through a separate command: $ zappa update dev
  4. API Gateway url will be displayed on cosole something like: https://abcdefgh.execute-api.us-east-1.amazonaws.com/dev

Configure the skill in the Alexa developer console and test

  1. Working with the Alexa console requires Alexa Developer console access
  2. Go to Alexa Skills list page
  3. Click the Add a New Skill button
  4. The skill configuration screen opens

Skill Information section

  1. Set the Name of the skill and Invocation Name

Interaction Model section

  1. Paste in the Intent Schema
  2. Create Custom Slot type
  3. Paste in the Sample Utterances

Configuration section

  1. Select HTTPS as the Service Endpoint Type
  2. Paste API Gateway url

SSL Certificate section

  1. Select the option that reads: My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority

Test Section

Now test the skill by typing: What is news

Also, you can check This video by John Wheeler which shows how to deploy your speech assets configuration to the Alexa Developer Portal.

That's all! If you are using a browser that supports WebRTC for micophone input (Chrome, Firefox or Opera), you may use echosim to test your script - simply log in with the same credentials you used to deploy your Skill.

Testing and Code Coverage

To run tests and check code coverage, execute below command in root project directory

$ tox

This will create python 2.7 virtual environment and execute the tests

To clean run the tests execute $ tox --recreate

Zappa Commands

  • Logs - $ zappa tail dev
  • Limit the output returned and eliminate the HTTP noise in the logs by using the --since 1m and --non-httpcommand options: $ zappa tail dev --since 1m --non-http
  • Remove the AWS Lambda function, API gateway: $ zappa undeploy dev

Sphinx Commands

  1. Go to <root_folder>/docs and execute below commands to create HTML documents
  2. Unix: $ make html
  3. Windows: make.bat html