Skip to content

Latest commit

 

History

History
executable file
·
79 lines (48 loc) · 7.98 KB

2-lambda-function.md

File metadata and controls

executable file
·
79 lines (48 loc) · 7.98 KB

Build An Alexa Quiz Game Skill

Voice User InterfaceLambda FunctionConnect VUI to CodeTestingCustomizationPublication

Setting Up A Lambda Function Using Amazon Web Services

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.

  1. 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.

  2. 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.

  3. 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.

  4. 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.)

  5. 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.

  6. 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."

  7. Click Create Function in the bottom right corner. You will need to scroll down to find Create Function.

  8. 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.

  9. 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.

  10. 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.

  11. Click the Skill Information Link.

  12. Copy the Application ID provided in the main window. This is also known as a skill ID, and is unique to your skill.

  13. 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.

  14. 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".

  15. 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.
  1. 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.

  2. 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.

  1. After you're done, the ARN value for this Lambda function should be in the top right corner of the page. Copy this value for use in the next section of the guide.