Creating an Alexa skill using the Command Line Interface (CLI)
If you’re into building skills, you’re probably familiar with Alexa Skills Kit’s Command Line Interface, which lets you create and manage your skill using the CLI, like updating the interaction model, and the backend code. You can of course manage these directly through the Alexa Developer Console, and AWS respectively, but CLI is a much faster workflow.
There are two ways to create a new Alexa skill using the ASK-CLI. You can use AWS Lambda as your backend, or if you are new and would like to keep things simple initially, you can use Alexa Hosted.
With an Alexa-hosted skill, your code is available inside a code editor in the Alexa developer console itself, so you can edit and deploy changes to your code quickly, without needing to set up an AWS account.
Let’s look at how you can use the ASK-CLI to create a new skill using each of these two backend options.
Option 1: Using AWS Lambda as the backend
Prerequisites
You can find more information about the prerequisites on the Amazon Developer Documentation here.
Step 1: Create a new skill using the ASK-CLI with AWS Lambda as backend
- Assuming you already have the ask-cli setup (see prerequisites) , open up the terminal, and type the following -
$ ask new
This will provide the following prompts -
- Select the runtime -
Node.js V8
orPython3
- Choose
hello world
as the template to get started with - Type in your skill name -
ice-cream-soda
(or a name you prefer)
This will create the skill locally on your machine.
Step 2: Deploying the skill (Interaction Model and AWS Lambda)
Type the following into the command line -
$ cd ice-cream-soda
$ ask deploy
This may take a few minutes, and if everything goes well, you will get a confirmation that Your skill is now deployed and enabled in the development stage. Try simulate your Alexa skill skill using "ask dialog" command.
You can verify by logging into the Alexa developer console at developer.amazon.com/alexa/console/ask. Your backend code has been deployed as an AWS Lambda function using the AWS IAM user you set up in #2 of the prerequisites, which you can verify by logging into your AWS Console at console.aws.amazon.com/lambda.
Step 3: Pushing the skill code to GitHub for collaboration
- Create a new repo on GitHub.com, say
ice-cream-soda
. If curl is your thing, you can also type this on the command line -
$ curl -u 'YOUR_GITHUB_USER_NAME' https://api.github.com/user/repos -d '{"name":"YOUR_NEW_REPO_NAME"}'
When you use ask new
to create a new skill using one of the templates (say hello world), the git remote for the skill directory that's created for you points to https://github.com/alexa/skill-sample-nodejs-hello-world.git
. If you’d like to push your skill code on GitHub, you need to remove the .git
directory, which removes the remote. Let’s do that now.
2. Remove the .git
directory (hidden by default) to reset the remote origin, which is by default set to https://github.com/alexa/skill-sample-nodejs-hello-world.git(https://github.com/alexa/skill-sample-nodejs-hello-world.git).
$ rm -r .git
You may get a warning asking if you’d like to override removal of .pack
and .idx
files. Typeyes
to confirm.
You can now deploy your skill code to a GitHub repo with no problems, without breaking the ask deploy
process to deploy the skill to AWS Lambda/Developer Console.
- Initialize Git
$ git init
- Add a remoteto point to the new GitHub repo
$ git remote add origin git@github.com:YOUR_GITHUB_USERNAME/YOUR_GITHUB_REPO_NAME.git
// example:
// git remote add origin git@github.com:ajot/ice-cream-soda.git
- Push to GitHub
$ git add .
$ git commit -m "first commit"
$ git push -u origin master
Option 2: Using Alexa Hosted as the backend
You can also use the Alexa Skills Kit CLI to create a skill using Alexa Hosted as the backend, instead of AWS Lambda using the create-hosted-skill(https://developer.amazon.com/docs/smapi/ask-cli-command-reference.html#create-hosted-skill-command) command. Support is available for Node.js only for Alexa Hosted through the CLI.
Step 1: Create a new skill using the ASK-CLI with AWS Lambda as backend
- Open up the terminal, and type the following -
$ ask create-hosted-skill
- Type in your skill name:
kiwi-cream-soda
- Select the runtime -
Node.js V8
orPython3
- Alexa hosted skill is created. Do you want to clone the skill project to current working directory? (Y/n)
- Type
yes
Your skill has now been automatically deployed on the Alexa Developer Console using Alexa Hosted. For future deployments, just use ask deploy
from within the skill directory.
Step 2: Pushing the repo to GitHub
When you use ask create-hosted-skill
to create a new skill, the git remote is set to an AWS Code Commit service https://git-codecommit.us-east-1.amazonaws.com
. We need to add another remote, so we can push to both GitHub without breaking the AWS Code Commit service. We will do this in step by adding a new remote (Step 2 below), and then updating the Push URLs for the remotes (Step 3 below)
- Create a new repo on GitHub.com, say
kiwi-cream-soda
. If curl is your thing, you can also type on the command line -
$ curl -u 'YOUR_GITHUB_USER_NAME' https://api.github.com/user/repos -d '{"name":"YOUR_NEW_REPO_NAME"}'
- Type the following into the terminal -
$ cd kiwi-cream-soda
$ nano .git/config
Make a note of the Push URL. We will need this in the next step. This will be something like -https://git-codecommit.us-east-1.amazonaws.com/.....
CTRL + X to exit the nano editor.
$ git remote add github git@github.com:YOUR_GITHUB_USERNAME/YOUR_GITHUB_REPO_NAME.git
// example:
// git remote add github git@github.com:ajot/kiwi-cream-soda.git
- Configure the Push URLs - for GitHub, and the original push URL for deploying the skill code to Alexa Hosted.
Set remote URL for GitHub
$ git remote set-url --add --push origin git@github.com:YOUR_GITHUB_USERNAME/YOUR_GITHUB_REPO_NAME
//example:
// git remote set-url --add --push origin git@github.com:ajot/kiwi-cream-soda.git
Set remote URL for AWS Commit Service to enable the ask deploy
workflow.
$ git remote set-url --add --push origin YOUR_PUSH_URL_FROM_GIT_CONFIG_FILE_FROM_STEP_2
//example:
// git remote set-url --add --push origin https://git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxx-xxxxx-xxxxx
- Verify the Push URL’s have been updated for the remote origin
[remote "origin"]
url = https://git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxx-xxxxx-xxxxx
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = git@github.com:<YOUR_USER_NAME>/kiwi-cream-soda.git
pushurl = https://git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxx-xxxxx-xxxxx
CTRL + X to exit the nano editor.
- Deploy to Alexa Hosted, and push to GitHub
$ git add .
$ git commit -m "first commit"
$ ask deploy
This will deploy the skill to Alexa Hosted, and also push to GitHub.
Updating the ASK-CLI
$ npm install -g ask-cli
$ ask -v