Developer Console

Lambda Overview (VSK Echo Show)

The Lambda function serves as the video skill's backend. You can update the reference Lambda code locally, use the CLI tool to update, rebuild, redeploy the project, and automatically push your Lambda to AWS.

How It Works

All Lambda scripts are locally stored in the project, under your ./lambda/src folder. They are pushed to the cloud when you deploy your video skill using the CLI tool. If you successfully deploy the video skill, you will be able to locate your entire Lambda function as a single file, in the AWS console. There, you can search for your Lambda:

Search for your Lambda on the AWS console

Click on your function name (<your-project>-lambda). Your lambda function lives inside the index.js file.

Your Lambda code

By using the CLI tool, you only need to focus on updating specific scripts stored locally (for example, you can update the video content database.js script), update, redeploy the Lambda component, and push the updated Lambda to the cloud.

The Lambda function can receive directives from Alexa as JSON, process them, and then return a response with the expected JSON. Directives are JSON messages that contain instructions about performing specific actions, like getting metadata for a video. Currently, there is a JSON object that functions as a video content database embedded within the reference Lambda code.

To configure the Lambda function to interact with another existing database that you own, modify the database access class to query this database and return data structured in the same way as in the reference code. The rest of the Lambda code can remain unchanged as it responds dynamically to the contents returned by the database access layer.

By default, the reference Lambda uses the Gracenote catalog (named as 'ontv'). See Use your Own Catalog Name if you own a catalog that has already been ingested by Alexa, and want to use that catalog instead.

Features

The reference Lambda supports the following main features:

Feature By Example
Search Video id Search for Stranger Things
Search for Psych Season 1
Search for Black Panther
Search Actor Name Search for movies by Liam Neeson
Search for movies by Jamie Foxx
Search Genre Search for Comedy movies
Search for Action movies
Search for Adventure movies
Search Multiple video metadata fields, such as Actor + Genre Search for Action movies by Liam Neeson
Search for Comedy TV Series by Jennifer Aniston

Note that on the search results page, you can also say something like:

Select the second one
Play number 1
Quick Play Video Name Watch Stranger Things
Watch Psych Season 1 Episode 1
Watch Black Panther
Quick Play Actor Name Watch movies by Liam Neeson
Watch movies by Jamie Foxx
Quick Play Genre Watch Comedy movies
Watch Action movies
Watch Adventure movies
Quick Play Multiple video metadata fields, such as Actor + Genre Watch Action movies by Liam Neeson
Watch Comedy TV Series by Jennifer Aniston
Channel Navigation Tune to PBS
Tune to NBC
Browse and List Selection Explore different categories listed
Explore additional categories under More Categories by saying:

Select Highly Rated
Select More Categories

Note that the transport controls are specified by the web player included in the reference software.

Lambda Installation and Updates

Your Lambda needs to be hosted on AWS, which is handled by the CLI tool during the installation process. It also needs to be configured in the skill manifest, which is something that you might want to do in the developer portal. Typically, however, the infrastructure CLI tool included in the project automatically sets this up for you.

By using --deploy, the infrastructure CLI tool creates and deploys the Lambda function. This happens during the reference video skill setup.

Use --update --lambda to update and deploy the Lambda code during your development cycle. This significantly speeds up the development process.

For a manual Lambda installation process, see Set up Lambda Manually (Optional).

The Lambda must be configured in the video skill's manifest. The infrastructure CLI tool included in the project, handles that for you. However, if you choose a manual configuration, you must visit the Alexa developer console and follow the steps under Set up Lambda Manually (Optional).

Set Up Lambda Manually (Optional)

If you want to install your Lambda manually (rather than through the CLI tool), you must follow a different process:

  1. Navigate to the local ./lambda folder of your project.
  2. Run npm run release.
  3. Create an AWS Lambda function in the same region where you wish to deploy your video skill, following the steps mentioned here.
  4. Copy the compiled Lambda code from ./lambda/dist/lambda to the AWS Lambda function created in Step 3.
  5. In your Lambda execution role created in Step 3, add the following policy:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "s3:GetObject",
            "dynamodb:BatchGetItem",
            "dynamodb:BatchWriteItem",
            "dynamodb:PutItem",
            "dynamodb:DeleteItem",
            "dynamodb:GetItem",
            "dynamodb:Scan",
            "dynamodb:Query",
            "dynamodb:UpdateItem",
            "logs:CreateLogGroup",
            "logs:CreateLogStream",
            "logs:PutLogEvents"
          ],
          "Resource": ["*"]
        }
      ]
    }
    
  6. Create a DynamoDB database for your Lambda, to store data for pagination using the following specs:

    "PaginationDatabase": {
        "Type" : "AWS::DynamoDB::Table",
        "Description": "Holds data for Pagination",
        "Properties" : {
            "TableName" : {
                "Fn::Sub": [
                    "${ProjectName}-pagination-table",
                    {
                        "ProjectName": {
                            "Ref": "ProjectName"
                        }
                    }
                ]
            },
            "AttributeDefinitions" : [
                {
                    "AttributeName" : "token",
                    "AttributeType" : "S"
                }
            ],
            "KeySchema" : [
                {
                    "AttributeName" : "token",
                    "KeyType" : "HASH"
                }
            ],
            "ProvisionedThroughput" : {
                "ReadCapacityUnits" : "5",
                "WriteCapacityUnits" : "5"
            }
        }
    }
    

Next Steps

See Lambda Customization.


Last updated: Oct 29, 2020