Skip to content

AWS Lambda

Dmitriy Chechyotkin edited this page Dec 1, 2020 · 2 revisions

AWS Lambda

AWS Lambda enables developers to host their Alexa voice skills on the Amazon's serverless cloud.

For most developers, the Lambda free tier is sufficient for the function supporting an Alexa skill. The first one million requests each month are free. Note that the Lambda free tier does not automatically expire, but is available indefinitely.

JAICF provides a built-in support of AWS Lambda for every Alexa skill powered with JAICF.

Also it's possible to use an AWS built-in DynamoDB database to transparently persist the users' data using context client map.

How to use

1. Create your Alexa skill

Learn how to create the Alexa skill using JAICF.

2. Define Lambda handler

Every AWS Lambda has to have handler - a special function that should be invoked each time the user interacts with your Alexa skill. To make a handler from your JAICF scenario just create a new public class:

class AWSLambda: AlexaLambdaSkill(botApi = gameClockBot, dynamoDBTableName = "GameClock")

Make sure you've provided dynamoDBTableName in the case your bot persists some data across different user's sessions.

3. Append shadowJar

Build your project using shadowJar plugin to include all libraries inside the resulting JAR file. Append this to your build.gradle:

plugins {
    kotlin("jvm") version "1.3.71"
    id("com.github.johnrengelman.shadow") version "5.0.0"
}
tasks {
    compileKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
    build {
        dependsOn(shadowJar)
    }
}

4. Create new DynamoDB table

If your JAICF project persists some data between different user's sessions you have to create new DynamoDB table.

  • Create new DynamoDB table with the same name you've defined on the step 2
  • Type "id" in the Primary key

5. Create new AWS Lambda

  • Create new AWS Lambda
  • Select Java 11 in runtime settings
  • Add DynamoDB full access policies to the Execution role on Permissions tab if your project uses DynamoDB
  • Append Alexa Skills kit trigger to the created lambda with Alexa skill ID you've created on the step 1
  • Build and upload your JAICF project's JAR file in the Function code section
  • Define a full path to the handler in the Runtime settings, for example com.justai.jaicf.examples.gameclock.channel.AWSLambda::handleRequest
  • Copy ARN from the top right corner and paste it in the Alexa Console > Endpoint > AWS Lambda ARN
Clone this wiki locally