Deine Alexa Dashboards Einstellungen
Vielen Dank für Ihren Besuch. Diese Seite ist momentan nur auf Englisch verfügbar. Wir arbeiten an der deutschen Version. Vielen Dank für Ihr Verständnis.

Deploy a Sample Custom Skill to AWS Lambda

The Alexa Skills Kit provides several samples of custom skills written in Node.js (JavaScript) and Java. An easy way to get started working with these samples is to deploy and test them as AWS Lambda functions on AWS Lambda (a service offering by Amazon Web Services).

The samples are available in GitHub repositories. For details about getting the samples and the specific samples included, see Using the Alexa Skills Kit Samples (Custom Skills).

This document describes how to deploy the samples as Lambda functions. For an overview of AWS Lambda, see What Is AWS Lambda?. For more about using Lambda with the Alexa Skills Kit, see Creating an AWS Lambda Function for a Custom Skill.

If you do not already have an account on AWS, go to Amazon Web Services and create an account before completing the procedures below.

For the Node.js samples, see these sections:

For the Java samples, see these sections:

Preparing a Node.js Sample to Deploy in Lambda

The Node.js samples are available on GitHub in the Alexa organization. The samples use the Alexa Skills Kit SDK for Node.js.

To deploy a Node.js sample as a Lambda function, you first need to create a zip file containing the .js files provided in the sample. The Node.js samples use the Alexa Skills Kit SDK for Node.js, so you need to also include these dependencies in your zip file. If you have not already installed Node.js and NPM, follow these steps first.

  1. Download or clone the GitHub repository for the sample. The Node.js samples are all in separate repositories in the Alexa GitHub organization.

    If the sample is available as a Lambda blueprint, you can skip down to step 4 and create the Lambda function. It is still useful to download the repository for easy access to the interaction model files.

  2. In a terminal or command line, navigate to the src directory for the sample and enter this command:

     npm install --save alexa-sdk
    

    This installs a node_modules directory containing the SDK dependencies.

  3. Select all the contents of the src folder, and create a zip file.

    The zip should contain the files, but not include the src folder. The index.js file must be at the root of the zip. The zip should include the node_modules directory.

  4. See Creating the Lambda Function for the Sample to create the new function and upload the code.
  5. See Creating a New Skill for the Sample on the Developer Portal to register the sample skill on the developer portal.
  6. See Updating the Application ID in the Code for the Sample to update the sample with the newly-generated application ID.

Preparing a Java Sample to Deploy in Lambda

To deploy a Java sample as a Lambda function, you must first build the sample using Maven, then upload the resulting JAR file.

Requirements

  • Apache Maven - The Java samples are set up with a Maven script that builds a .JAR file containing all the required dependencies. This automatically includes the Java library needed for the sample.

    Before attempting to build a Java sample, make sure you have a current version of Maven installed. You can download Maven from the Apache Maven page

  • A development environment with Java Development Kit (JDK) 8 or later.

Building the Java Sample

  1. Download or clone the amzn/alexa-skills-kit-java GitHub repository.
  2. Open a command line and navigate to the samples folder in the zip. This directory contains the pom.xml file.
  3. Run the following command:

     mvn assembly:assembly -DdescriptorId=jar-with-dependencies package
    

    This creates a .JAR file called alexa-skills-kit-samples-1.0-jar-with-dependencies.jar in the target directory.

  4. See Creating the Lambda Function for the Sample to create the new function and upload the code.
  5. See Creating a New Skill for the Sample on the Developer Portal to complete the setup so you can test the sample.
  6. See Updating the Application ID in the Code for the Sample to update the sample with the newly-generated application ID.

Creating the Lambda Function for the Sample

Once you have either a zip containing the Node.js code or a compiled .JAR for the sample, do the following:

  1. Log in to the AWS Management Console and navigate to AWS Lambda.
  2. Create a new Lambda function in the US East (N. Virginia) or EU (Ireland) region.
  3. To quickly set up one of the blueprint samples, select the sample from the list of blueprints. The following samples are available as blueprints:

    Selecting one of these blueprints automatically imports the code into the Lambda console.

  4. Configure the new function with the following settings, depending on whether your are deploying a Node.js or Java sample:

    Setting Node Value Java Value
    Triggers Click the outlined box select Alexa Skills Kit. Click the outlined box select Alexa Skills Kit.
    Name A descriptive name for the function. A descriptive name for the function.
    Description A description for the function. A description for the function.
    Runtime Node.js Java 8
    Lambda function code Select the Upload a .ZIP file option and upload the zip file you created.

    If you selected one of the blueprints (such as alexa-skill-kit-sdk-factskill), the code is already filled in.
    Select the Upload a .ZIP file option and upload the file alexa-skills-kit-samples-1.0-jar-with-dependencies.jar in the samples/target folder.
    Handler index.handler The SpeechletRequestStreamHandler class implemented for the sample. For example, for the Hello World sample, this would be helloworld.HelloWorldSpeechletRequestStreamHandler. See the Readme.md for the specific sample to get this name.
  5. Select the Role for the function. This defines the AWS resources the function can access.
  6. Make note of the Amazon Resource Name (ARN) for your new Lambda function. The ARN is displayed in the upper-right corner of the function page.
  7. Continue with the next step: create a new skill for the sample on the developer portal.

Defining a New Role for the Function

The role specifies the AWS resources your function can access. To create a new role while configuring your function:

  1. For Role (under Lambda function handler and role), select Create new role from template(s).
  2. Enter the Role Name.
  3. From the Policy templates list, select Simple Microservice permissions.

Creating a New Skill for the Sample on the Developer Portal

Register a new Alexa skill on the developer portal. For details, see Registering and Managing Custom Skills in the Developer Portal.

Use the following information when registering the new skill:

Setting Value
Invocation Name Any valid invocation name.
Name Any valid name.
Endpoint Select the AWS Lambda ARN (Amazon Resource Name) option, then either North America or Europe and enter the ARN for your function.
Interaction Model Each sample includes an interaction model in the speechAssets folder for the sample.

Copy the JSON from IntentSchema.json into the Intent Schema box and copy the text from SampleUtterances.txt into the Sample Utterances box.

For details about defining the interaction model, see Define the Interaction Model in JSON and Text.

Updating the Application ID in the Code for the Sample

Once the sample is registered as a skill, you need to update the Application ID in the code of the sample to match the ID assigned to the new skill. This ensures that the Lambda function only accepts requests sent by the skill you registered.

  1. Log on to the Developer Portal.
  2. Navigate to the Alexa section by clicking Apps & Services and then clicking Alexa in the top navigation.
  3. In the Alexa Skills Kit box, click Get Started.
  4. Find the skill in the list and click Edit.
  5. On the Skill Information page, copy the Application Id shown.
  6. Update code for the sample with the ID you copied:
    • For a Java sample, specify the application ID with a supportedApplicationIds.add() method call in the SpeechletRequestStreamHandler class for the sample.
    • For a Node.js sample, specify the application ID in the APP_ID variable at the beginning of the index.js file.
  7. Upload your updated code to your Lambda function.
    • For Node.js, create an updated zip file for your code and upload to your Lambda function.
    • For Java, rebuild the sample JAR file for your code and upload it to your Lambda function.

Next Steps