Developer Console
Thank you for your visit. This page is only available in English at this time.

Lambda Overview

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 Step

See Lambda Customization.