In the first step of this guide, we built the Voice User Interface (VUI) for our Alexa skill. On this page, we will be creating an AWS Lambda function using Amazon Web Services. You can read more about what a Lambda function is, but for the purposes of this guide, what you need to know is that AWS Lambda is where our code lives. When a user asks Alexa to use our skill, it is our AWS Lambda function that interprets the appropriate interaction, and provides the conversation back to the user.
-
Go to http://aws.amazon.com and sign in to the console. If you don't already have an account, you will need to create one. If you don't have an AWS account, check out this quick walkthrough for setting it up.
-
Click "Services" at the top of the screen, and type "Lambda" in the search box. You can also find Lambda in the list of services. It is in the "Compute" section.
-
Check your AWS region. AWS Lambda only works with the Alexa Skills Kit in two regions: US East (N. Virginia) and EU (Ireland). Make sure you choose the region closest to your customers.
-
Click the "Create a Lambda function" button. It should be near the top of your screen. (If you don't see this button, it is because you haven't created a Lambda function before. Click the blue "Get Started" button near the center of your screen.)
-
There are two boxes labeled "Author from scratch" and "Blueprints". Click the radio button in the box titled "Blueprints" then choose the blueprint named "alexa-skill-kit-sdk-factskill". We have created a blueprint as a shortcut to getting everything set up for your skill. You can search for a blueprint using the provided search box. This blueprint adds the alexa-sdk to your Lambda function so that you don't have to upload it yourself.
-
Configure your function. This screen is where we will enter the important parts of our Lambda function. These values will only ever be visible to you, but make sure that you name your function something meaningful.
-
Set up your Lambda function role. If you haven't done this before, we have a detailed walkthrough for setting up your first role for Lambda. If you have done this before, set your Existing role value to "lambda_basic_execution."
-
Click Create Function in the bottom right corner. You will need to scroll down to find Create Function.
-
Configure your trigger. Look at the column on the left called "Add triggers", and select Alexa Skills Kit from the list. If you don't see Alexa Skills Kit in the list, jump back to step #3 on this page.
-
(Optional, but recommended) To secure this Lambda function follow the instructions found here: alexa.design/secure-lambda-function
-
Scroll back up and click Save.
-
Click the box that has the Lambda icon followed by the name of your function and scroll down to the field called "Function code".
-
Copy and paste the provided code into the Lambda function code box. We have provided the code for this skill on GitHub. Delete the contents of the code box, and paste the contents of the new code. Click "Save".
-
You should see the Amazon Resource Name (ARN) for this function in the top right corner of the page. (You may need to scroll back up.) Copy the ARN value for this Lambda function by clicking the small copy button; we will use this ARN in the next section of the guide.
-
Go back to the Amazon Developer Portal and select your skill from the list. You may still have a browser tab open if you started at the beginning of this tutorial.
-
While on the Build tab, select the Endpoint tab on the left side navigation panel.
-
Select the "AWS Lambda ARN" option for your endpoint. You have the ability to host your code anywhere that you would like, but for the purposes of simplicity and frugality, we are using AWS Lambda. (Read more about Hosting Your Own Custom Skill Web Service.) With the AWS Free Tier, you get 1,000,000 free requests per month, up to 3.2 million seconds of compute time per month. Learn more at aws.amazon.com/free. In addition, Amazon now offers AWS Promotional Credits for developers who have live Alexa skills that incur costs on AWS related to those skills.
-
Paste your Lambda's ARN (Amazon Resource Name) into the textbox provided for Default Region.
-
Click the Save Endpoints button at the top of the main panel.
-
Click the "Next" button to continue.