Deploying Only the Interaction Model for OU Alexa Skill
Deploying Only the Interaction Model for OU Alexa Skill
Deploying only the Interaction Model for you Alexa Skill when using Amazon Alexa Skill ASK CLI 2.x via a bash script using AWS Command Line Interface.
Join the DZone community and get the full member experience.Join For Free
In the new ASK CLI 2.x that has just been recently released, I found that the choice to deploy only the interaction model seems to have disappeared. In this article, I will show you how to regain this powerful time-saving capability back.
The Value of Deploying Only The Interaction Model
This option is important to me as I do a lot of local debugging. To save time I used to deploy only the interaction model from my local machine when I do simple minor changes, especially on the utterances, slot types, and values.
The interaction model is a lot faster to deploy than the lambda code itself.
Furthermore, the lambda code is the one that you are least likely to deploy often if you are using a local debugger. This is because the endpoints for the lambda calls are at your localhost with your local codebase and all code changes are immediate!
To make it even more important, if you change the interaction model, there is no other choice but to deploy it as most of the speech and NLU processing is done in the cloud. There is some trickery you can do, like cut and paste the model files between local and the ADC and or using test tools like the one from bespoken.io. But as some of you can appreciate, you will eventually need to do it the “real” way which is to do a full deployment.
I find it a waste of time to do a full deployment when all it takes is a few seconds to deploying just the interaction model!
I was also challenged by Jeff Blankerberg on Twitch to find a way to do this and I am always open for a challenge! BTW if you have not followed Jeff on his Twitch channel, you should! https://www.twitch.tv/jeffblankenburg. Other Amazing Alexa Twitch streamers include Jeff Nunn, Karthik Ragubathy, and Justin Jeffress to name a few!
Nevertheless, it is still not as straight forward as an option in the previous ASK CLI 1.x so on top of digging into the solution live on my twitch stream at twitch.tv/goldzulu (I believe I’ve spent almost 3 hours online fighting against one of those stupid bugs!), I decided to write this blog so others can benefit from the time saved!
Please note that my solution is geared towards the Mac OSX so if you are a Windows Powershell user, get a Mac! Just kidding, but seriously, you may have to change a few things here and there.
I also assume that you:
- Have ASK-CLI 2.x installed
- Have AWS CLI installed (especially for S3 use)
- Have an S3 bucket set up where AWS CLI can copy files to
- Use the default profile for both of the above
- Have bash installed and running in your Command Line Interface
- Know how to customize a bash script for your own needs
My solution is wrapped up in a simple bash script that you can place at the root of your Alexa Skill project.
Please note that I have also used a convenient node.js script that I have written a while back in my earlier blog post. The script extracts the Alexa Skill skill id which is used a lot as a required argument in the SMAPI CLI commands. You can find out how I came out with the script here in this blog post https://dzone.com/articles/syncing-local-alexa-skills-json-files-with-alexa-d
If you want to just get the gist, you can find the gist of the file here https://gist.github.com/goldzulu/b2f80676bed088242228417aab71f715 You might need to make it executable by doing a chmod 755 ./get-skill-id.js
The Bash Script
I will explain the fragments of my interaction model update script below. I’ve named the bash script m.sh
The first part of the script is just doing the setup of a few variables and its value.
Modify the path to where you have placed the get-skill-id.js (downloaded above)
Specify where your S3 bucket is. The S3 bucket is needed to act as a temporary place where you zipped up the interaction model going to reside.
Specify where the S3 base URL. This is so that Alexa SMAPI API can grab the file from the specified https location.
Specify the expiry time for the length in time of which you want the interaction model zip file to be available in your S3 bucket. I have used the day after, before 23:59 hours UTC as an expiry time as an example. You can change it or hardcode this to a future date if you want. The date command below might not work on non-Mac OSX machines so you might want to find an equivalent. You can easily test if this is working or not by doing date -v+1d -u +%Y-%m-%dT23:59:00Z at your command line.
The next part is optional but for me, it saves me a lot of time. I copied the base en-US locale to all the other English locales that I care about such as en-GB. Add as many English locales that you want duplicating here. Doing this also allows me to only modify the en-US locale and let the script automate the copying to the other locales. More time-saving!
Next, we will zip up the interaction model. From this moment on I will call the interaction model, the skill package because in ASK CLI 2.x all the interaction model assets live in the skill-package directory. The skill package directory also contains the important skill.json file.
Next, we will copy the zipped up-skill package to the S3 bucket. I set the expiry date as well as make it public readable (temporarily)
The Golden Nugget
Now, this is the part where the hidden command is revealed! I’ve found the command ask smapi import-skill-package to do exactly what’s needed to update the interaction model! You might want to remove the last — debug option if you don’t want too much output but it did help me in troubleshooting if things go wrong.
The above steps will also deploy your skill.json file which if you are using local debugging, you might have changed the endpoints in the Alexa Developer Console (ADC). You can either change the local skill.json file before deployment with the local development endpoints or change the endpoint at ADC after you have deployed.
Sounds like a hassle right? Fear not, I have also prepared another node.js convenient script that will allow you to change the endpoints at ADC directly from your command line! But this has to wait for my next blog post coming up soon!
You can get the above bash script in the gist here https://gist.github.com/goldzulu/8cd2bcdf26f1a25370326091bd6385b6
That’s it! Congratulations, you are now officially on the way to save 10,000 hours of your Alexa Skill development life!Overall, I believe that a good developer should always strive to find the fastest most convenient and productive way to do day to day dev-ops tasks. So I will continue to find a faster and more productive way to do stuff and will disseminate the knowledge.
Opinions expressed by DZone contributors are their own.