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 a 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 Lambda is where our code lives. When a user asks Alexa to use our skill, it is our 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. Check out this quick walkthrough for setting up a new AWS account.
-
Choose "Services" at the top of the screen, and type "Lambda" in the search box. You can also find it in the list of services. It is in the "Compute" section.
-
Check your AWS region. Lambda only works with the Alexa Skills Kit in four regions: US East (N. Virginia), EU (Ireland), US West (Oregon) and Asia Pacific (Tokyo). 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.
-
Click on "Author from scratch". We will configure our Lambda function next.
-
These values will only ever be visible to you, but make sure that you name your function something meaningful. "samplePythonPetMatch" is sufficient if you don't have another idea for a name.
-
From the "Runtime" dropdown select the python version your system supports. This tutorial and sample code works with either Python 2.7 or 3.6. To check the python version, try the following command in a terminal
$ python --version Python 2.7.10
-
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, you only need to select the Existing role.
-
Click Create function.
-
-
Configure your trigger. There are many different AWS services that can trigger a Lambda function, but for the purposes of this guide, we need to select "Alexa Skills Kit." from the left hand side.
Once you have selected Alexa Skills Kit, scroll down and find the Skill ID verification section. Although you will want to paste your skill's ID in the Skill ID field, however for this tutorial, click Disable. Click the Add button in the lower right. Click the orange Save button in the top right corner.
-
Finish configuring your function. Click on your function's name (you'll find it in the middle) and scroll to the bottom of the page, you'll see a Cloud9 code editor.
We have provided the code for this skill here. To properly upload this code to Lambda, you'll need to perform the following:
-
This skill uses the ASK SDK for Python for development. The skill code is provided in the lambda_function.py, and the dependencies are mentioned in requirements.txt. Download the contents of the lambda/py folder.
-
On your system, navigate to the lambda folder and install the dependencies in a new folder called “skill_env” using the following command:
pip install -r py/requirements.txt -t skill_env
-
Copy the contents of the
lambda/py
folder into theskill_env
folder.cp -r py/* skill_env/
-
Zip the contents of the
skill_env
folder. Remember to zip the contents of the folder and NOT the folder itself. -
On the AWS Lambda console, change the code entry type drop-down to Upload a .ZIP file, upload the zip created in the previous step and click on Save.
(Optional) Follow the ASK Python SDK Getting Started documentation, to check alternative ways of installing the sdk and deploying to AWS Lambda console.
-
-
(Optional) Click the Configure test events dropdown menu on the top of the page.
-
Select 'Alexa Start Session' from the 'Event Template' dropdown.
-
Type
LaunchRequest
into the 'Event Name' field. -
Click the orange 'Create' button at the bottom of the page
-
Click the Test button at the top of the page. 1. You should see a light green box with the message: Execution result: succeeded at the top of the page.
-
As a final step, copy the ARN value from the top right corner of the screen. You will need this value in the next section of this guide.