Alexa
Getting Started – Alexa SKills Kit Command Line Interface (ASK CLI)

Getting Started – Alexa SKills Kit Command Line Interface (ASK CLI)

It is very convenient and easy to build and manage a new Alexa Skill through Alexa Developer Console. But it gets out of hand and becomes difficult to manage once your Alexa Skill starts growing in size especially if you are using AWS Lambda to host your skill. At this time ASK CLI comes very handy. The ASK Command Line Interface (ASK CLI) is a tool for you to manage your Alexa skills and related AWS Lambda functions. With ASK CLI, you have access to the Skill Management API, which allows you to manage Alexa skills programmatically from your computer’s command line.

Especially once your Lambda code grows in size, it cannot be managed from browser window. Either you can setup AWS CLI or ASK CLI to manage your Lambda function. But the benefit of ASK CLI is ASK CLI can be used to create, read, update, and test both Alexa skills and connected AWS Lambda functions, as well as to submit skills for certification or withdraw them. In the upcoming sections we will explore how to setup and use ASK CLI and its benefits.

 




 

First of all, we will setup ASK CLI on your Windows Machine. Follow the steps given below to get started:

STEP 1Prerequisites

Amazon Developer Account

If you don’t already have an Amazon Developer Account, then visitAmazon Developer Website and create an Amazon Developer Account.

This is the place where your Alexa Skills are created. ASK CLI will need you to authenticate and link your developer account at the time of setup/initialization.

 

Node.js and Node Package Manager (NPM)

ASK CLI is available as an NPM package. ASK CLI requires you to have Node.js (version greater than 4.5) and NPM installed on your machine. NPM automatically get installed with Node.js.

To check if you already have Node.js (version greater than 4.5) installed on your machine, run following command node -v in cmd. If you already have Node.js installed it will print the version number of Node.js installed.

If you don’t have node.js installed then visit Node.js Website and install it.

 

GIT

If you will use a template to create a new alexa skill through ASK CLI, git must be installed on your machine. Git is a version control system for tracking changes in computer files and coordinating work on those files among multiple people.

If you don’t have git installed on your machine, then visit Git Website and install it.

 

Amazon Web Services Account

If you are going to use AWS Lambda to host your skill, then you will need an Amazon Web Services (AWS) account. If you don’t already have an AWS account, then visit AWS Website and create an account.

You will need an AWS account for creating IAM User in step 2.

 

STEP 2Set up AWS IAM user

If you will host your skill on AWS Lambda i.e you will use AWS lambda to host the logic of your skill, then follow this step otherwise skip this step. If yes, then you need to set up an IAM user in AWS account with certain permissions and provide credentials of that user to ASK CLI while setup/initialization in Step 3. Now follow the points given below to set up an IAM user.

  • Go to AWS website. Sign in with your AWS account.
  • Open the IAM Identity and Access Management Console.
  • A menu should be visible on the left-hand side. Click on Policies.
  • ASK CLI ONE
  • On the next screen, click on Create Policy button on top of the page.
  • ASK CLI TWO
  • ASK CLI THREE
  • On the next screen, select JSON tab and paste the below policy into the given space replacing existing text there
  • Review and Create the policy with the name of your choice.
  • Now click on Users from the same left-hand menu as of Policies. And then click on Add User button on top of the page.
  • ASK CLI FOUR
  • On the next screen, provide a User Name for the user and select the AWS access type, you want to provide to the user. There are two access types available one is Programmatic access and other is AWS Management Console access. Since we need this user to log in from ASK CLI, just select Programmatic access.
  • ASK CLI SIX
  • Now click on Next: Permissions button. Select Attach existing policies directly from the given options and then select the Policy created above from the list shown. After that click on Next: Review and Create: User button.
  • ASK CLI SEVEN
  • After successful creation of User, you will be provided with the access key and secret access key. You can click Show to see the key. Download the CSV file or you can even mail those credentials to your registered email id. Please save these credentials at a safe place since you are provided with these credentials for only one time. After that, you can never access them or you will have to generate a new access key.
  • Finally, you have created an IAM user for your ASK CLI operations.

 

But Why need to set up an IAM user?

While setup/ initialization of ASK CLI, it needs the AWS credentials to access the AWS Lambda. AWS Identity and Access Management (IAM) is a web service that helps you securely control access to AWS resources. In above steps, first of all, we defined a policy that provides restricted access to AWS resources namely “IAM”, “lambda” and “logs”. Then we created a user and attached that policy to that user. Now, this user can access the resources defined in the above policy with the permissions specified. The benefit of creating a separate user is that you can control and manage access to your AWS resources as per your requirements. And as we need this user primarily for performing a task related to ASK CLI i.e AWS lambda, we defined this user in that way. And now can use credentials of this user while setup of ASK CLI.

 

NOTE:

In most of the tutorials including Amazon Alexa docs, you will find ” ask-* “ in resource value inside the policy. This restricts access of the user to the lambda functions created using ASK CLI. But if you try to access skill created on Developer Console using ASK CLI, permission will be denied. So to have access to all the skills whether created using ASK CLI or Developer Console, I have used ” * “ instead of ” ask-* “ in resource value in the above-given policy.



STEP 3Install and Initialize ASK CLI

Now that we have all prerequisites and credentials in place, we can install and initialize the ASK CLI. Follow the points given below:

  • We will use NPM to install ASK CLI. Open cmd and type the below-given command.
  • npm install -g ask-cli
  • After ASK CLI gets successfully installed. Run the next command given below.
  • ask init
  • It will show a message stating that there is no AWS credential setup and it will ask you to set up the credentials. Select ” yes “. And then provide the credentials we got in Step 2 of this post. If you don’t want to use AWS Lambda, then select ” no “.
  • ASK CLI cmd
  • After successful setup of AWS credentials, cmd will redirect you to a browser window, where you have to log in with your Amazon Developer Account credentials.
  • ASK CLI Sign In
  • After successful login into your developer account, it will show a message ” Sign in was successful. Close this browser and return to the command line interface “. After that close the browser and return to the cmd.
  • An ASK Profile named default must be created for you. We will discuss more about ASK Profile in the later section of this post. With this, you have successfully installed and initialized the ASK CLI in your system.

 

NOTE:

After your first time set up of AWS credentials, a credentials file is created in .aws directory of your system. Every time ASK CLI runs any command, it accesses AWS credentials from this file. You find this file in the following location: %USERPROFILE%\.aws\credentials

 

STEP 4Explore ASK CLI Commands

There are various commands available to manage Alaxa Skills in ASK CLI but we will look at three main commands which you will use often, which are as follows.

ask new [--template {template-name} [--url {url}]] [-n|--skill-name {name}]]

This command creates a new skill project containing directories and files that represent new skill in the local file system under the current directory. All new skill projects created using the new command can be immediately deployed with the ask deploy command.

By appending --template followed by template-name to ask new command, you can specify the name of a pre-defined template to use to create a new skill. When template-name is omitted, ASK CLI provides a prompt for choosing a template from a list. Optionally, you can specify/append --urlfollowed by url to provide your own list of templates.

By appending --skill-name followed by skill-name to ask new command, you can assign name to the skill. When you specify –template and omit –skill-name, the skill name defaults to the template name. When not using –template, if –skill-name is omitted, ASK CLI provides a prompt for specifying the skill name.

ask deploy [-t| --target {target}]

Using this command inside the skill project directory will deploy your skill to your developer account. If you have your AWS credentials set up and skill configured to use AWS Lambda, this command will automatically deploy your code as well.

By appending --target followed by the target to ask deploy command, ASK CLI will update the specified target with the local version. If no target is specified, then the existing skill, including the skill manifest, interaction model, lambda, and in-skill products will all be updated. Accepted values for target are: all, lambda, skill, model, and isp. The default target is all, if not specified. By using --target you can just update a part of your skill i.e you can either update the aws lambda code or the skill project on Alexa Developer console.

ask clone [-s|--skill-id {skillId]

Use this command to create a local skill project directory from the development stage of an existing skill. This command will download the entirety of your skill, including the skill manifest, interaction model, and skill code (if your skill uses AWS Lambda). After cloning, you can make changes locally then deploy them easily using the ask deploy command.

There are many other commands available which you can refer by visiting ASK CLI Reference page.

 

ASK Profile

In Step 3, while initialisation of ASK CLI we created a ASK Profile. An ASK profile represents the AWS profile plus the Amazon developer account used for Alexa skill deployments. ASK profile and AWS profile can have different names, and you can have multiple ASK profiles associated with a single AWS profile, if desired. You might do this if you have skills in multiple Amazon developer accounts, but the skills are backed by AWS Lambda functions in one AWS account.

When running other commands in the CLI, you can specify the name of the ASK profile you want to use using the --profile option.



We have successfully setup the ASK CLI and also had a look on some of the ASK CLI commands. Now it is upto you, how you will use ASK CLI and leverage its advantages. To have a more detailed look at ASK CLI and its commands you can visit below given pages.

 


If you face any problem in the tutorial above, you can always leave a reply or reach me through the chat option given in bottom right corner of the window.

Share this Story

Leave a Reply

Your email address will not be published. Required fields are marked *

About Me


I'm a college student pursuing B.tech. I created this website (Blog) to share my learnings with the people who search for the same content/knowledge.