Hello world! of Alexa skills

Ankur Jain
7 min readNov 30, 2020
Before creating a masterpiece, the artist should have a grasp on the tools at his disposal.

Prerequisite

Before you dive into this article if you haven’t read through my story on Alexa fundamentals i would strongly encourage you to do so.

Overview

In order to easily make an Alexa skill, there are a few prerequisites which we will be talking about in this tutorial. Specifically we will be needing

  1. Amazon echo device. There are multiple types of alexa devices available and we will talk about them later but to keep things simple we can just start with Amazon echo dot. Here is the link in case you want to purchase one.
  2. Amazon developer portal account: This is where we can create the VUI (voice model) for our skill.
  3. Amazon aws account: This is where we will host the backend service for our skill.
  4. ask-cli: We will use the cli provided by Amazon alexa team, to quickly get up, running and deploy our skill.

Amazon echo device

I wanted to point out that we do have a simulation tool inside amazon developer portal account which lets you test your Alexa skill. But i would still recommend to buy a device for two major reasons.

  1. The testing simulation currently does not work with audio streaming. So if your skill consist of any audio streaming you will not be able to test it using the simulator.
  2. This is a personal opinion in which i feel that testing on an actual device gives you some sense of achievement and pushes you to make better and more skills.

Amazon developer portal account

Amazon developer portal is the house where all your skills will live. Once you have the account you can use the portal to

  1. Create the skill
  2. Build the skill
  3. Specify your backend endpoint.
  4. Test your skill
  5. Specify the metadata associated with your skill
  6. Get your skill certified
  7. Checkout various analytics around your skill.

Click here to create a developer portal account.

Amazon aws account

We are using amazon aws to create the backend endpoints for our Alexa skills. Some of the reasons for choosing amazon aws are:

  1. Very simple and straightforward to start.
  2. Great integration of aws lambda with Alexa skill. AWS lambda is totally serverless and you don’t have to worry about managing server.
  3. Using aws lambda is a low cost option as you get ~1M requests free per month.
  4. You can read more about aws lambda pricing here.

Click here to create a new aws account.

Ask Cli

There are two primary ways of creating an Alexa skill

  1. UI:
  • FrontEnd/VoiceModel: Go to developer.amazon.com. Follow the wizard and Alexa UI to create the appropriate interaction model.
  • Backend: Go to console.aws.amazom.com and create a lambda on console.

2. ask-cli:

  • FrontEnd/VoiceModel: Use ask-cli to create a basic structure which can be deployed go developer.amazon.com using ask-cli itself.
  • Backend: Use ask cli which in turn uses cloud-formation to create the infrastructure and also enables you to write the code, which can later be deployed to aws account using ask cli.

We will be using ask-cli for working on the skills because of the following benefits:

  1. Code organization: Using ask cli allows you a great code organization, which lets you view your interaction model, skill backend infrastructure and code all at one place.
  2. Simple deployment: Just by running a simple command you can deploy the interaction model to Alexa developer portal and your backend infrastructure to aws.
  3. Version control: Since everything is managed via code, it can be version controlled using GIT.

Installation

  1. ask-cli required node.js installed. Nodejs installation instructions can be found here.
  • If you are using mac and home-brew, nodejs can be easily installed with command:brew install node

2. ask-cli installation requires you have administrator permissions on your machine.

  • On Windows, open PowerShell with the Run as Administrator option. On Linux or macOS, use sudo.

3. Install ask-cli using npm: npm install -g ask-cli

Configuration

In this section we will configure our ask cli so that we have profiles(credentials) saved for the developer portal and the aws account.

  1. Go to your aws account and create an IAM user. After creating a new IAM user make sure you save the access key and password created locally.
  • Click here to see how to create an IAM user.

2. Go to the terminal and enter the command: ask configure

3. Connecting to developer portal

  • It will ask you to create a new profile or overwrite existing profile. In case you haven’t created any profile choose new profile.
  • Enter if you want the profile as “default”
  • The command will open a browser window and it will ask you to enter the credentials for your developer account.

4. Connecting to aws

  • The cli will ask if you want to link your AWS account in order to host your Alexa skills. Enter yes
  • It will ask you if you want to create a new aws profile or overwrite an existing one. Choose create a new one and enter to choose default.
  • Enter the Aws Key Id.
  • Enter the Aws Key secret.

5. That’s it! Your ask cli configuration is complete.

Hello World!

Phew! The boring setup part is over and we will actually create, build and deploy an Alexa skill in this section.

  1. Create the Alexa skill
  • Open terminal and run the command: ask new
  • Choose the programming language you will use to code your skill
  • NodeJS (There are options for python and java as well, which we will cover some other day)
  • Choose a method to host your skill’s backend resources
  • AWS with CloudFormation (This option will create a skill-stack.yml which can hold the infrastructure configuration for your code. For example you can define your aws lambda, dynamodb etc in your skill-stack.yml file)
  • Choose a template to start with
  • Hello world (There are other templates too. After going through this tutorial i will encourage you to create more skills using other starting templates to see what kind of boilerplate they are generating)
  • Please type in your skill name
  • aryabrains hello world (Feel free to choose any name you want for your skill)
  • Please type in your folder name for the skill project.
  • aryabrainshelloworld (Feel free to choose the project folder name)
  • That’s it! The cli has done its magic and created a bare bones skill for you.

2. Understanding the folder structure

  1. LICENSE.txt
  2. ask-resources.json (This file have the information which folder contains your code, which folder contains the skill infrastructure and which folder contains the skill metadata. Unless you are changing the default location of any of those things you do not need to make changes to this file)
  3. infrastructure/cfn-deployer
  • skill-stack.yml (This file will contain the infrastructure code for the skill. This file is the cloud formation template in which you can define the various resources you want to use for your skill like aws lambda, dynamodb etc)

4. lambda

  • index.js (This file contains the handler which is called by your Alexa skill)
  • package.json (This file will contain all your nodejs dependencies)
  • util.js (This utility file contains a method to generate a presigned url for s3. If you are not using s3 for your skill in any capacity, then go ahead and remove this file)

5. skill-package/assets

  • en-US_largeIcon.png (Large icon for your skill)
  • en-US_smallIcon.png (Small icon for your skill)

6. skill-package/interactionModels/custom

  • en-US.json (This is the interaction model file for your skill in en-US. If you want a skill in en-IN locale, simply create a file with name en-IN.json and then you can write your en-IN interaction model in that file.)

7. skill-package

  • skill.json (This is the skill manifest file. This file contains publishing information like summary, example phrases, information about interfaces used in the skill, etc. )

3. Deploying your skill

  1. Before you can deploy your skill open the skill-package/interactionModels/custom/en-US.json file. Replace the invocation name with the skill name you used while creating the skill. In my case it was: “aryabrains hello world”
  2. In order to build and deploy your skill, simply navigate to the skill’s root directory and run the command:ask deploy
  • This commmand will essentially do four things:
  • Deploy the skill metadata along with your interaction model to your developer.amazon.com account.
  • Build the skill code.
  • Deploy the skill code to your aws account.
  • Enables the skill for your testing

3. Once the command is done, you should see the message

  • “Skill is enabled successfully”

4. Testing your skill

  1. Go to Alexa console. Click here.
  2. Click on the skill name you just created. In this case i am choosing aryabrains hello world.
  3. Go to Test tab, and then type “open <skill-name>” for ex: “open aryabrains hello world”
  4. You should see the response “Welcome, you can say Hello or Help. Which would you like to try?”
  5. Congratulations! You were able to deploy your Hello world skill.
  6. In case you have an actual device which is linked to your amazon account, you can invoke this skill on the device as well.

5. Github

  1. The code for this tutorial is here.

Next Steps

If you have come this far, give yourself a pat on your back. You have successfully deployed your first Alexa skill. In the next tutorial, we will go over the Alexa console UI, see how to make some modifications to the interaction model and changes to your backend code. Till then, chao chao!

--

--

Ankur Jain

Hi, I am a software developer and i like to learn and share :)