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 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. "samplePythonColorPicker" 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 3.7 or 3.9. To check the python version, try the following command in a terminal
$ python --version Python 2.7.10
-
Change default execution role. From the “Execution role” section you can select “Create a new role with basic Lambda permissions”. For more details, we have a detailed walkthrough for setting up your first role for Lambda.
-
Click Create function.
-
-
Configure your trigger. Expand the ‘Function overview’ window and click on + Add 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" from the drop-down menu.
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 orange Add button in the lower right.
-
Finish configuring your function. 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, navigate to the Code tab and click on the Upload from button. Select “.zip file” from the drop-down menu to 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 Test tab and select ‘Create new event’.
- Type
LaunchRequest
into the 'Event Name' field. - Select 'Alexa Start Session' from the 'Event Template' dropdown.
- Click the ‘Save’ button at the bottom of the page
- Click the Test button at the top of the page.
- You should see a light green box with the message: Execution result: succeeded at the top of the page.
- Type
-
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.