Zero to Hero, Part 10: The ASK Command Line Interface (CLI)


– Hey, and welcome back. My name is Andrea, and I
work as a Tech Evangelist on the Amazon Alexa team. In this video, we’re gonna
move away from the web browser and go towards the command line. A lot of you hate working on the browser, especially advanced developers that are used to using the
command line for everything. Well, there’s good news for you, Alexa supports the command line and has a ton of different
APIs that are available to you so you can automate basically any task that has to do with building Alexa skills. So in this video, we’re gonna show you how to use the ASK CLI and do some basic and the
most important things with it. So without further ado, let’s get started. So in order to get started with the CLI, we’ll need a couple prerequisites. The first obvious one is the
Amazon Developer account. Now, we’ve been using it until now, but it’s worth mentioning. The second one is Node.js and NPM. Depending on how you install Node.js, it may or may not be included. The third one, since we’re using
Alexa-hosted skills, is Git. Because when you clone
an Alexa-hosted skill, it’s going to implicitly create a Git repo in your local directory, and then, the ASK CLI. Now, in this video tutorial,
I’ve already installed it, but I haven’t configured it. So follow that link, alexa.design/askcli, to find the instructions
on how to install it, and now, we’ll configure it together. So how do I configure the ASK CLI? Well, everything starts with ask, which is the way that we invoke the CLI, init, for initialize. You’ll see it opens a browser tab with which we will need to
log in and authenticate. So let me put in my credentials, and let’s log in. Sign in was successful. Close browser and return to
the command line interface. Great, let’s go back, and now, it’s gonna ask us if we want to associate an AWS profile. Now, since we’re using
Alexa-hosted skills, we haven’t worked with
AWS, so we can select no. However, if you are using
AWS for your own skills, make sure that you select yes and you associate it with
your AWS credentials. It will automatically pick them from the .aws directory
in your Home folder. So I’m gonna proceed with no, and we’re done. Now, our ASK CLI is configured. Now, as I said earlier, we’ve
been working on the browser, so let’s move all of our working directory to a local folder here, and we do that a bit like with Git. We would do git clone. We do ask clone. You’ll see it’ll auto-suggest
all the skills we have. In our case, it’s just
the hello world skill which is actually Happy_Birthday. Done, it’s cloning it, cloning all the models, cloning the code, all of the languages that we’ve added, and we’re finished. So let’s move into this
folder and make an edit. So let’s cd into, or
I’ll actually show you that it has appeared here, and now, we can cd into Happy_Birthday, and you’ll see we have our skill here. So let’s open the folder and go to, for example, the localization
strings just to show you an example of a typical
edit that we would do and then deploy to our skill backend. So let’s modify the English file, and instead of saying Welcome back, let’s say Nice to see you again, comma. That way we have a nice pause between the again and the name. Let’s save that file, and again here we’re working with Git, and I can show you this
by doing Git branch. You’ll see we have a dev branch,
a master branch and a prod. And they’re kind of like the
equivalent of the three buttons we have in the code tab of
the Alexa-hosted skills, which is save, deploy and promote to live. So how do we take this change
of the welcome back message and deploy it to our
original Alexa-hosted skill? Well, like with Git we have to commit it. So let’s do a git status
to see what changed. Oh, the localization has changed. So let’s git commit,
and we’ll add a message which is improved welcome back message. And now since we’ve made the changes, we can do deploy. Now rather than doing a git push, we do an ask deploy, and if we were just to write ask deploy, it would deploy our whole project folder to the Alexa-Hosted repo. This means it would rebuild the model. It would update our code. It would basically update the whole skill. Since we’re only changing the backend, we can also specify a target. Ask deploy-t target lambda ’cause we only wanna deploy the backend. Now it’s deploying the code. And we’re done. So how do we check the code? Well, let’s just go to
our developer console, and double check that
the change has been made. Let’s go into the code tab here. We are now in the localization.js file, and we’ll see that
instead of welcome back, we have “Nice to see you again, Andrea.” Awesome. So this is how we would deploy
any changes to our backend, and if you make any changes
to your interaction model you can just do ask deploy
which will update everything or ask deploy target, interaction model. What’s left to do? Well, now we’ve cloned an existing skill, but what if we wanted to start our whole journey from the command line? Well, there’s a command for that as well. So rather than work
with an existing skill, we can just do ask create hosted skill. We can specify a run time, a skill name, which in this case I’ve chosen hosted-skill created from CLI. And auto clone. Auto clone will make sure
that when you create the skill using this command, it’ll
also clone it automatically to our local folder. Keep in mind this create hosted skill is what you need to create
an Alexa-hosted skill. If you want to create a
normal lambda-hosted skill on AWS or anything else,
you have to do ask new. And another thing to keep in mind, when you do use this command
to create a hosted skill, you either have to specify
all of these parameters or none of them. Make sure you keep that in mind. I have specified all three. Let’s hit enter. And now it’s creating
our Alexa-hosted skill. As with the developer
console, it takes awhile because it’s provisioning
all of the resources, and deploying our whole project. So it’ll take a little bit, but in the meantime,
we can go to our skills and check, hey, look, a new skill. Hosted skill created from CLI. We can go into here. And we can go to the code
tab and see what’s happening. Oh, AWS resources are being provisioned, and everything was started
from a simple command. Once all of this is done,
it’s going to appear, and our command line will also update. Hosted skill provisioning finished. And now our command is done. Great. So now we know how to create a skill. But how do we test a skill? So how do we test a skill and make sure that it’s working correctly? Well, let’s see where we are here. Yeah, so we are in our original folder. Let’s do an ask dialog. When you do an ask dialog, which allows you to
converse with your skill, you can do, you always
have to specify a locale. Ask dialog locale,
especially if your skill has more than one locale,
in which case ours does, and we will specify en-US. Now it’ll default to the skill that we’re currently working in. Right now, we’re in our
happy birthday skill, and I’ve created our second
skill inside this directory. You usually wanna CD out of it, and create a new skill from there. But here we can do open happy birthday. And this is exactly like what
would happen in the simulator where you have Alexa responding. It’ll tell you what’s
happening, and you can, for example, say help, as you would and stop as you would. It also has a nifty little way to show you that the session has ended. So let’s control + C out of there, and we’re done. So hopefully in this short tutorial you’ve seen how to use the
CLI and how you can use it to automate your work and not have to always be
on the browser to develop. This is a great way to also
version control your code and work with Git and
also use these commands to maybe have a build process or an automated deployment process as your skill gets more robust. With that, I wish you good
luck in your CLI adventures, and see you in the next video.

Add a Comment

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