When your 7-year-old gets a mood ring on vacation and constantly asks what a certain color means, you make an Alexa skill for it.
- This is heavily based on the Alexa Fact Skill Sample for Node.
- It demonstrates how to create a Lambda function for handling Alexa Skill requests.
- It also demonstrates using custom slot types to handle a finite set of known values
To run this example skill you need to do a few things.
- Pull down the code and run
npm install
to install the Alexa SDK for Node.js. - Deploy the example code in AWS Lambda.
- Configure the Alexa skill to use AWS Lambda.
- Go to the AWS Console and click on the Lambda link. Note: ensure you are in us-east or you won't be able to use Alexa with Lambda.
- Click on the Create a Lambda Function or Get Started Now button.
- Select Blank Function under Blueprint on the next screen.
- On the next screen, "Configure triggers", click the outlined box and select "Alexa Skills Kit" in the dropdown that appears. Click next.
- Name the Lambda Function "moodRing" (or whatever you want). Add a description if you like.
- Select the runtime as Node.js. As of this writing, Lambda supports Node 6.10.
- Go to the the src directory, select all files and then create a zip file, make sure the zip file does not contain the src directory itself, otherwise Lambda function will not work.
- Change Code entry type to "Upload a .ZIP file" and then upload the .zip file to the Lambda. No changes to the encryption helpers or Environment variables are needed for this skill.
- Keep the Handler as index.handler. This refers to the function exported in the index.js file in the zip.
- Under Role, if this is your first Alexa skill, select "Create new role from template(s)", call it "lambda_basic_execution", and select "Simple Microservice permissions" in the Policy templates dropdown. If you have done this before, you probably already have a "lambda_basic_execution" role, so select "Choose an existing role" in the Role dropdown and the lambda_basic_execution role for Existing role. More can be found on this Alexa Skills Kit doc page (as of July 2017):
- No Tags are needed, and leave the Advanced settings as the defaults.
- Click "Next" and review the settings then click "Create Function".
- Click the "Actions" dropdown and select "Publish new version". Add a description that is meaningful to you, it's not used for any other purpose. Note: Only published versions can be used by your Alexa Skill.
- Copy the ARN from the top right to be used later in the Alexa Skill Setup.
- Click the "Actions" dropwdown again and select "Configure test event". For "Sample event template", scroll down to Alexa -> Alexa Start Session. I'm sure you can get more advanced here, but this basic step is necessary because subsequent uploads of your skill code will run a test, and it will fail if you leave the Hello World test as the default.
Note: Each time you upload a new ZIP of your code, you will need to publish a new version and copy the new ARN in the top right corner. A version number is incremented at the end of each ARN, like this: arn:aws:lambda:us-east-1:486600117452:function:testSkill:1
Another important note: You also need to go to the "Triggers" tab, select "Add trigger", click the gray box and select "Alexa Skills Kit" each time you publish a new version of your code. Not sure why that is not saved.
Pay it forward If you find this process to be different or I've missed a step, feel free to send a pull request. This process is not at all intuitive, and there is a lot of old and conflicting information out there. Good luck!
- Go to the Alexa Console and click Add a New Skill.
- Set "Mood Ring" as the skill name and "mood ring" as the invocation name, this is what is used to activate your skill. For example you would say: "Alexa, Ask mood ring what red means."
- Select the Lambda ARN for the skill Endpoint and paste the ARN copied from above. Click Next.
- Copy the custom slot types from the customSlotTypes folder. Each file in the folder represents a new custom slot type. The name of the file is the name of the custom slot type, and the values in the file are the values for the custom slot.
- Copy the Intent Schema from the included IntentSchema.json.
- Copy the Sample Utterances from the included SampleUtterances.txt. Click Next.
- [optional] go back to the skill Information tab and copy the appId. Paste the appId into the index.js file for the variable APP_ID, then update the lambda source zip file with this change and upload to lambda again, this step makes sure the lambda function only serves request from authorized source.
- You are now able to start testing your sample skill! You should be able to go to the Echo webpage and see your skill enabled.
- In order to test it, try to say some of the Sample Utterances from the Examples section below.
- Your skill is now saved and once you are finished testing you can continue to publish your skill.
User: "Alexa, ask mood ring what red means."
Alexa: "You are excited and adventurous. Go get 'em, tiger."