Amazon Alexa Skill Tutorial
Learn how to create your own Alexa skills from a pro! Follow this step-by-step Alexa skill tutorial to build your own skill for Amazon's Alexa. Get familiar with Amazon Lambda, Skills Portal, test and customize all in this alexa guide.
Dec 15, 2018 • 10 Minute Read
Build your first Alexa skill
Each Alexa skill is comprised of an “Invocation Name,” which you can think of as your app name, a set of “Intents,” the phrases that map to each intent, and the software that can detect the intent and return an appropriate result.
We are going to create an adaptation of the classic “Hello, World!” program. Once we finish, Alexa will learn this "skill" and be able to appropriately respond to new voice commands that apply to it.
Building your first skill will comprise of four steps.
- First we’re going to copy the “Hello, World!” code into Amazon Lambda, which will be responsible for running the code.
- Next we’re going to set up our skill in the Amazon Alexa Skills Developer Portal, and link our lambda account to that skill.
- Then we’re going to test using the Amazon service simulator and on an Alexa-enabled device.
- Lastly, we’ll walk through the steps of customizing your skill to your needs.
I put together a list of resources at https://bit.ly/alexaskill, which is a public Instapaper folder I've set up to make sharing my list of links easier. The slides will refer to each of these links. I’d recommend having this open in a separate tab, so you can refer back to the links easily.
Step 1
- Open the AWS Lambda console
- Login using the same Amazon account to which your Alexa device is linked (recommended) or create a new account.
Enter the name of your Lambda function. This name needs to be unique. For now, you can simply use “HelloWorld". In the top right, it should say “N. Virginia”. If that’s not the case, please select “US-East (N. Virginia)” from the dropdown menu.
Why North Virginia? As of the time of this writing, the Alexa Skills Kit is only hosted in East US (N. Virginia.)
Copy the Hello World application source code.
Back in Lambda, you’re going to scroll down a bit and paste the code you copied from GitHub into the large text box under “Lambda function code”.
Scroll down a bit further to the “Lambda function handler and role” section. Set the role to “lambda_basic_execution”.
If this is your first time using Lambda, you’ll have to create the “lambda_basic_execution” role. You can do that by selecting the first option “* Basic Execution” and clicking the blue button on the next page. After you take that step, you should be able to select “lambda_basic_execution”.
Once you’ve created the function, click on the “Event Sources” tab. Then click the blue “Add event source” link, then select “Alexa Skills Kit” from the modal dropdown.
Please note if you’ve never signed up for the Amazon Developer Portal, you’ll have to do that first before the “Alexa Skills Kit” will appear from the Event Sources dropdown. Please also make sure to use the same Amazon account as the one that's being used with AWS and your Alexa device.
Step 1 Done
Keep the Amazon Lambda tab open though, we’ll come back to it!
Step 2
Open the Amazon Developer Skills portal and log in with the Amazon account connected to your Alexa device.
Click the yellow “Get Started >” button under “Alexa Skills Kit”. Then, click the yellow “Add a New Skill” button on the next page.
The name of your Amazon Alexa skill must be unique for your account, and the invocation name is what you’ll use to activate the skill. “Alexa, tell to say Hello, World”.
If you can't think of anything else, no worries! You can use "Hello World" as the invocation name. Click the yellow “Next” button when you’re ready!
This is where we tell the skill which intents we support and which words will trigger each intent. Get ready to copy-paste.
Open the Hello World intent schema and copy all of the text in the box.
Back in the Amazon Skills portal, paste the copied schema into the "Intent Schema" field.
Open the Hello World sample utterances and copy all of the text in the box.
Back in the Amazon Skills portal, paste the sample utterances you copied into the Sample Utterances field. Click the yellow “Next” button after you’ve pasted the Sample Utterances.
Change the radio button from “HTTPS” to “Lambda ARN”, and select the “No” radio button under "Account Linking". Now we’ll have to go and grab the Lambda Amazon Resource Name (ARN) from our Lambda tab. You still have that open, right?
The ARN is at the top right of the Lambda function page. I have it selected in the image above. You’ll want to copy the selection next to "ARN". This field looks somewhat like a source path.
Paste the ARN into the text field, and press “Next”.
Step 2 Done
Step 3
After you click “Next” on the “Configuration” tab, you should be on the “Test” tab. Under the “Service Simulator” portion, you’ll be able to enter a sample utterance to trigger your skill. For the “Hello, World” example you should type something like “Say hello world.” On the right you should see the output from the Lambda function you created: “Hello, World!”
If you got the correct output using the Service Simulator, try it on the Amazon Echo. We were using “last name” as the invocation name in this presentation, but you should use the invocation name you set in step 2c.
Alexa, tell Hello World to say Hello World
Step 3 Done
Step 4: Customize
Go back to the “Interaction Model” tab in the Alexa Skill Developer portal, and edit the words on the right of “TestIntent” with the words you would like to say to Alexa. An example might be “Who is the coolest person on earth?”. In this case, you would prompt by saying “Alexa, ask who is the coolest person on earth?”
Next we’ll customize the output.
- Go to the "Code" tab in Lambda.
- Scroll to line 104 and replace "Hello, World" with your output (Keep quotes around your output).
- Click "Save".
- Test in the Amazon Developer Portal.
Step 4 Done
Congratulations, you just created your first Alexa skill! 👏👏 Keep making more skills to enable Alexa to perform new tasks.