Posted on |
Let’s start creating a simple Alexa Skills with the famous “Hello World” using AWS Lambda. To start off, we need the following accounts:
I will not write much details about this “Hello World”, ill be creating a separate blog for it to make it easy to run up a simple Hello World Alexa Skills App.
Sign in on your Amazon Developer Account, select Amazon Alexa then go to Your Alexa Dashboards the click Alexa Skills Kit Get Started. Hopefully you are on this page ready to Add a New Skill.
Click Add a New Skill. First step is the Skill Information. Fill the Name and Invocation Name. In my case I name the skill as “AlexaChamp.com Hello World”. For Invocation Name I used “gigamike”. Invocation Name is the name of your Alexa Skills app to launch. Example
Alexa…use gigamike…
The rest of fields on Skill Information just let the default values then Save. Click next. Second step is the Interaction Model. This is where we define the voice interface.
In the Intent Schema it requires a JSON format. In this section we define what intent to be triggered later on in our Lamda script.
{ "intents": [ { "intent": "HelloWorldIntent" } ] }
For our utterance, I defined 3 strings to trigger our intent “HelloWorldIntent”.
HelloWorldIntent say something HelloWorldIntent say hello world HelloWorldIntent say hello
So example.
Alexa…use gigamike…say something
Click save then next. On the third step “Configuration”, we will now define on what “script” to be triggered. So ready your javascript editor and login to your Amazon Web Services Account. In your AWS dashboard use the search box and search for “lambda”. Make sure that the selected region is on US East (N. Virginia) Region as not all region supports Alexa Skills trigger for Lambda. You should be on this page and ready to create a function.
Click Create Function. Define the function Name i.e. HelloWorld, Runtime just select the latest Node.js and for the Role select first Create a custom role. For the moment allow Lambda basic role, then go back and re-select Role as the newly create custom role or Choose an existing role i.e. in my case its lamba_basic_execution.
Click create function. On the next step this is where we will upload our NodeJS script and what event that will trigger the Lambda. Select Alexa Skills Kit on the left then save.
Let’s start on the code. We will be using “The Alexa Skills Kit SDK for Node.js“. Let’s first download NodeJS and install. On Github Alexa there is a ready made template Sample Nodejs Hello World. Download it and uncompress the skill-sample-nodejs-hello-world-master.zip. Now go to the /skill-sample-nodejs-hello-world-master/src/ directory and setup the libraries by executing
npm install
Let’s edit some code in the /skill-sample-nodejs-hello-world-master/src/index.js. I altered lines between 17 to 27
'SayHello': function () { this.response.speak('Hello World From AlexaChamp.com!'); this.emit(':responseReady'); }, 'AMAZON.HelpIntent': function () { const speechOutput = 'This is the Hello World Sample Skill from AlexaChamp.com. '; const reprompt = 'Say hello, to hear me speak.'; this.response.speak(speechOutput).listen(reprompt); this.emit(':responseReady'); },
Then save your file. Now we can set this script to our Lambda. Let’s go back to our Amazon Web Services Account Lambda function we created. Compress all files on/skill-sample-nodejs-hello-world-master/src/ as a zip file and we will be uploading the zipped file to AWS S3. On Amazon Web Services Account search S3
Create a bucket, in my end I created a bucket named alexachamp.com. Under bucket alexachamp.com I uploaded my zipped file.
Click the zipped file and check the file overview. We need to copy the URL of the zipped file.
And paste it to our Lambda function and save.
On the top right you will see an ARN source example arn:aws:lambda:us-east-1:768801405021:function:HelloWorld. Copy that and let’s go back to Amazon Alexa dashboard configuration where we left previously.
Click save and next. So we are now on step 4 in Alexa Skills kit which is the Test. Go to Service Simulator and enter our defined utterance. If everything is ok it will return a JSON with an outputSpeech Hello World From AlexaChamp.com!
Next step is the Publishing Information and Privacy & Compliance. Since this is just a test of a Hello World let’s ignore that for the moment. Let’s try it now to our Alexa Device. Make sure in your Amazon Alexa Account where you sync your Alexa device has the same email on your Amazon Developer Account in order for you to test on actual device.
Congratulation if you reach here. I know you have a lot’s of question why I did that, what is that etc. Again as much as possible I want to make this blog short and keep you on running your first Alexa Skills App using Lambda. Ill be creating a separate blog for more details about this Alexa Skills Kit. Have a nice day 🙂