Hello, Alexa: Building Your First Alexa Skill

Mai Nguyen
Fuzz
Published in
7 min readMar 7, 2017
Image from Amazon.com

Building voice user interfaces is a good skill to have as devices like the Amazon Echo and Google home gain popularity. Here’s a step-by-step tutorial on how to build an Alexa skill.

In this tutorial, we will be building an Alexa skill to ask what your favorite color is and record it to a database. The purpose of this tutorial is to walk through the flow of setting up an Alexa skill without getting too tangled up in the code, so it requires no coding ability since I’ve written all the code for you in the repository. We won’t be diving into the code this time, but I’m planning to cover that in a later post.

There are three different parts of an Alexa Skill. First is the wake word, this is what wakes up Alexa, and in most cases will be “Alexa”. The next part is the launch. This can be open, launch, begin, start, ask. Finally, we have the skill, or invocation name. This is the name of the skill you’re trying to open. Together, it would be something like: Alexa, open Spotify.

So how does Alexa decipher our words? Everything we say is sent to Alexa Voice Service, where it uses automatic speech recognition or natural language understanding to understand what we are saying.

Alright, now that we have the basics out of the way, let’s begin with building our first Alexa skill.

You will need an account on Amazon Web Services (AWS) and an account on Amazon Developer Services.

Jumping between two services can be a little confusing, especially if you don’t know the purpose of each one. So, let’s look at a high-level overview of the architecture for the Alexa skill we will build.

This is called the Skill Language Model or Voice UI (VUI). On the left, we have Lambda and DynamoDB. Both of these services live on AWS. Lambda is a serverless compute service and this is where all of your code will live. DynamoDB is a NoSQL database service and this is where data will be saved. DynamoDB isn’t required for building a skill (which is why it’s off to the side in the diagram) since you can store data temporarily per session. However, as soon as the session is over, that data disappears. So for this example, we will store data in DynamoDB.

To begin, go here and clone this repo. cd into the directory you just cloned, then cd into the /src directory. Runnpm install. Next, highlight all of the items in the directory including the /node_modules directory and compress it into a .zip file.

Now login into AWS and go to AWS Lambda. Click on “Create a Lambda Function” and then select “Blank Function”. When prompted, choose “Alexa Skills Kit” as your trigger.

On the next page, go ahead and name your function. I’ll be naming mine “alexaFavoriteColorExample” for this example. Make sure you have Node 4.3 selected as your runtime.

Underneath that, where it says “Code Entry Type”, select “Upload a .ZIP file” and upload the compressed file we made earlier.

Then, select “Create a custom role”

A new window will open with the role summary. You don’t need to change any of the default settings. Click on “Allow” and then the window should close.

After that, scroll to the bottom and hit “Next”. On the next page, review all of the information and make sure it’s correct. If it is, click on “Create Function”.

Now, let’s make sure that the code will run properly. click on the “Test” button select “Alexa Intent — Get New Fact”.

After running the tests, if everything went smoothly, you should see a green checkmark below your lambda function.

Next, let’s set up DynamoDB. We need to give DynamoDB access to the role we made earlier. Go to “IAM” on AWS and then click on “Roles” in the sidebar. Search for “lambda_basic_execution” (which is the role we made for our lambda function earlier) and then click on it.

Then click on “Attach Policy”

Search for Dynamo and select “AmazonDynamoDBFullAccess” and then click on attach policy. This will allow the role, which is attached to your lambda function, read and write access to DynamoDB.

Now, let’s create the DynamoDB database. On AWS, go to DynamoDB and then click on “Create table”. Name your table and then type in “UserId” as the sort key.

Alright, now that we’ve set up everything on AWS, let’s now move onto setting things up on Amazon Developer Services. After signing it, click on “Alexa” on the top navigation and then click on “Get Started” under “Alexa Skills Kit”. On the next page, click on “Add a New Skill”.

On the next page, type in the name of the skill and the invocation name. The name isn’t super important, it’s just for us to keep track of the skill. The invocation name is important as this is how you would open the app from Alexa.

“Alexa, open favorite color keeper”

When you finish typing in your name and invocation name, click “Next”. On this page, you will enter your intent schema and sample utterances. I’ve already provided these in the repository you cloned earlier. Go into the /alexa-demo/speech-assets directory and copy and paste the intent schema and sample utterances into the appropriate boxes.

Intents are similar to functions and slots are similar to arguments that you would pass into a function. You can see in the sample utterances that we pass a {color} slot (argument) to the intent (function) SetMyFavoriteColor.

After that you will need to grab your Lambda ARN (from AWS) and paste it into the provided input box.

You’re almost done! On the next page, you can test out your skill by typing in a sample utterance.

Congrats! You have finished building your first Alexa skill. You can now test your skill on your personal Amazon Echo device by following these instructions. If you don’t have an Amazon Echo but want to test out your skill verbally, you can use Echoism.

Mai Nguyen is a software engineer at Fuzz in Brooklyn, NY. There, she works on building APIs and CMSes for clients such as Oscar Mayer and Anheuser-Busch. Mai is a big fan of Laravel and slowly warming up to React. In her off time, she can be found signing up for a class on ClassPass or laughing at mediocre dad jokes.

--

--