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 three regions: US East (N. Virginia), US West (Oregon), 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 "Author from scratch". Then type a name for you lambda function, choose "Java 8" as the runtime.
-
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.
-
Once you have selected Alexa Skills Kit, scroll down. Under Configure triggers, select Enable for Skill ID verification. A skill ID Edit box should appear. We will now retrieve your Skill ID from the developer portal.
-
Now lets secure this lambda function, so that it can only be invoked by your skill. Open up the developer portal. Copy your skill's ID from the list of skills, it starts with "amzn1" and is located under the skill's name.
-
Click the Skill Information Link.
-
Copy the Application ID provided in the main window. This is also known as a skill ID, and is unique to your skill.
-
Return to your lambda function in the browser. You may already have this browser tab open from Step 11. Otherwise, open the lambda console by clicking here: AWS Console and select the appropriate function. Scroll down to Configure triggers, paste the Skill ID in the Skill ID edit box.
-
Click the Add button. Then click the Save button in the top right. You should see a green success message at the top of your screen. Now, click the box that has the Lambda icon followed by the name of your function. Scroll down to the box called "Function code".
-
Compile and package the provided code into the Lambda function. We have provided the code for this skill on GitHub.
- Downlod it, or clone this repo.
- Open a terminal or command line window, and navigate to the folder where you downloaded the source code
- Under lambda/custom you should find the pom.xml file, from this directory use the following Maven command to compile it and package it as a JAR with its dependencies.
mvn assembly:assembly -DdescriptorId=jar-with-dependencies package
- You can find the generated JAR in the 'target' folder.
-
Upload the code to Lambda Back in the AWS Lambda console, scroll down to 'Function Code' box, and from the 'Code entry type' drop box select 'Upload a .ZIP file'. Click the 'Upload' button, select the JAR with dependencies you created in the previous step using Maven. Click the 'Save' button in the top right corner.
-
Set your function's Handler In the 'Function Code' box you'll see a field labeled 'Handler' set the value as follows:
com.amazon.ask.quiz.QuizSkillStreamHandler
This is the fully qualified name for this skills main handler.