Alexa Skill & Google Action code that works on AWS Lambda

Overview

Jovo v4 Sample: Alexa Skill & Google Action on AWS Lambda

Jovo Staging and Deployment Deep Dive

Website - Docs - Marketplace - Template

This Jovo v4 sample app showcases the following features:

  • Platforms: A single code base that works on both Alexa and Google Assistant.
  • Staging: Uses a dev stage for local debugging and a prod stage that is deployed to AWS Lambda. Both stages use different Alexa Skill and Google Action projects.
  • Deployment: Uses the Serverless CLI for AWS deployment.

Learn how to get this project up and running in the getting started section. The stages and deployment section will help you deploy the project to the platform developer consoles and AWS.

Watch the video here:

https://www.youtube.com/watch?v=D4kYbr7Mm2s

Getting Started

Clone this repository and install all dependencies:

# Clone project
$ git clone https://github.com/jovotech/jovo-sample-alexa-googleassistant-lambda.git

# Go to directory
$ cd jovo-sample-alexa-googleassistant-lambda

# Install dependencies
$ npm install

The easiest way test the project code is to install the Jovo CLI and use the run command. Learn more in Jovo getting started docs.

# Install Jovo CLI globally
$ npm install -g @jovotech/cli

# Run local development server
$ jovo run

This will compile the code, run the local development server, and print out your individual Jovo Webhook URL that you can then use to access the Jovo Debugger.

The Debugger allows you to test your local code without having to create Alexa Skill and Google Action projects in the respective developer consoles. We'll do this in the stages and deployment section below.

Stages and Deployment

This project uses the Jovo staging feature that enables you to use multiple versions of your app, for example for local development and for a live version.

There are two stages available:

The jovo.project.js project config uses a dev and a prod stage for stage specific Alexa Skill and Google Action projects as well.

To get started, copy the .env.example file and rename it to .env.

Learn more below:

Alexa Developer Console

This guide will show you how to create two different Alexa Skill projects in the Alexa Developer Console:

  • One for the dev stage called Jovo Sample DEV using the invocation name my dev test app
  • One for the prod stage called Jovo Sample PROD using the invocation name my test app

It's also possible to stop after creating the dev Skill. More on that below.

DEV Skill

As explained in the Jovo Alexa installation docs, first install the ASK CLI and configure it by linking it to your Amazon developer account:

# Install ASK CLI globally
$ npm install -g ask-cli

# Configure ASK profile
$ ask configure

If you want to deploy to your default ASK profile, you don't need to change anything. If you want to use a different profile, modify the following in your .env file (after copying the .env.example file and renaming it to .env):

ALEXA_ASK_PROFILE_DEV=default

The Alexa Developer Console project docs show you in detail how to then deploy the project. Use the following two commands:

# Build platform specific files (default stage: dev)
$ jovo build:platform alexa

# Deploy these files to the Alexa Developer Console
$ jovo deploy:platform alexa

Since the .env does include an empty string for the Alexa Skill ID (for both dev and prod), a new Skill project will be created during the deployment.

ALEXA_SKILL_ID_DEV=
ALEXA_SKILL_ID_PROD=

After running the command, the CLI will print out the Skill ID of the newly created project. To keep the deployment linked to this project, copy the ID and add it to the .env file.

If you open the Alexa Developer Console, you should now see your project named Jovo Sample DEV in the list of Alexa Skills. The endpoint should be your Jovo Webhook URL. You can then open the testing tab and test the app using the invocation "my dev test app" (the invocation name is a stage specific model override that is added in the jovo.project.js file). Make sure that your local development server is running with jovo run before you start testing.

PROD Skill

The jovo.project.js file uses dev as defaultStage, so if you want to deploy to the prod stage, you either need to update that property or add the --stage flag to the commands:

# Build platform specific files (stage: prod)
$ jovo build:platform alexa --stage prod

# Deploy these files to the Alexa Developer Console
$ jovo deploy:platform alexa --stage prod

If you want to deploy to your default ASK profile, you don't need to change anything. If you want to use a different profile, modify the following in your .env file (after copying the .env.example file and renaming it to .env):

ALEXA_ASK_PROFILE_PROD=default

After successful deployment, you should now see your project named Jovo Sample PROD in the list of Alexa Skills in the Alexa Developer Console.

While the dev Alexa Skill uses the Jovo Webhook as endpoint, the code for the prod Skill will be hosted on AWS. You need to deploy it and update the following property in your .env file:

LAMBDA_ARN_PROD=arn:aws:lambda:us-east-1:111111111111:function:jovo-sample-prod-handler

It is necessary that you redeploy your Alexa Skill project again after updating the value above.

Actions on Google Console

This guide will show you how to create two different Google Action projects in the Actions on Google Console:

  • One for the dev stage called Jovo Sample DEV using the invocation name my dev test app
  • One for the prod stage called Jovo Sample PROD using the invocation name my test app

It's also possible to stop after creating the dev Action. More on that below.

DEV Action

As explained in the Jovo Google Assistant installation docs, you need to install the gactions CLI, ideally by following the official documentation by Google.

The Actions on Google Console project docs show you in detail how to then deploy the project. Since the Google Actions API doesn't allow for programmatic project creation, you need to access the console and create a project manually. Learn more in the official Google Assistant docs.

Then copy the newly created project ID and add it to your .env file (after copying the .env.example file and renaming it to .env):

GOOGLE_ACTION_PROJECT_ID_DEV=

For now, you only need to fill in the field for the dev stage.

You can then use the following two commands:

# Build platform specific files (default stage: dev)
$ jovo build:platform googleAssistant

# Deploy these files to the Actions on Google Console
$ jovo deploy:platform googleAssistant

After that, you can log see the changes in the Actions on Google console.

PROD Action

The jovo.project.js file uses dev as defaultStage, so if you want to deploy to the prod stage, you either need to update that property or add the --stage flag to the commands:

# Build platform specific files (stage: prod)
$ jovo build:platform googleAssistant --stage prod

# Deploy these files to the Actions on Google Console
$ jovo deploy:platform googleAssistant --stage prod

For this to work, you need to create a project in the Actions on Google console as explained in the previous section, copy the newly created project ID and add it to your .env file:

GOOGLE_ACTION_PROJECT_ID_PROD=

While the dev Google Action uses the Jovo Webhook as endpoint, the code for the prod Action will be hosted on AWS. You need to deploy it and update the following property in your .env file:

LAMBDA_ARN_URL=https://abcdefghijklmnopqrstuvwxyz.lambda-url.us-east-1.on.aws/

It is necessary that you redeploy your Google Action project again after updating the value above.

AWS

This guide will show you how to deploy the prod stage of your Jovo app to AWS Lambda using the Jovo Serverless CLI integration. The Serverless CLI needs to be installed globally like this:

$ npm install -g serverless

Learn more about how to create an AWS account and making the security credentials available to the CLI in the official Serverless docs.

You can make the keys accessible like this:

export AWS_ACCESS_KEY_ID=<your-key-here>
export AWS_SECRET_ACCESS_KEY=<your-secret-key-here>

After doing so, you can create a serverless.yaml file and then bundle and deploy the code using the following commands:

# Create serverless.yaml (stage: prod)
$ jovo build:serverless --stage prod

# Bundle and deploy code to AWS (stage: prod)
$ jovo deploy:code serverless --stage prod

If you run into any problems with the deployment, you can also use the following commands instead of deploy:code serverless:

# Bundle the prod stage source code
$ npm run bundle:prod

# Use the Serverless CLI for deployment
$ serverless deploy

Learn more about the npm scripts in the package.json file.

After successful deployment, you should be able to see the created function in the AWS Lambda console. If you did not update the service name in jovo.project.js, it should be called jovo-sample-prod-handler.

If the deployment doesn't work, it's possibly because the value for the Alexa Skill ID (which is needed for the verification happening in the Alexa Skills Kit Trigger) is undefined in your .env file. To get started, you could copy the existing dev Alexa SKill ID into the field and swap it out at a later point after creating a prod Skill project.

ALEXA_SKILL_ID_PROD=

To get information about your function, you can either open it in the console or run the serverless info command. Copy the ARN and add it to your .env file. This can then be used to rebuild and deploy your prod Alexa Skill with the Lambda function as endpoint.

LAMBDA_ARN_PROD=arn:aws:lambda:us-east-1:111111111111:function:jovo-sample-prod-handler

The function URL (that was added using the url: true parameter in the Serverless config, learn more in the official Serverless docs) is a newly introduced feature by AWS that makes Lambda functions accessible to outside services without the need to add an API Gateway endpoint.

Copy the function URL and add it to your .env file. This can then be used to rebuild and deploy your prod Google Action with the Lambda function as endpoint.

LAMBDA_URL_PROD=https://abcdefghijklmnopqrstuvwxyz.lambda-url.us-east-1.on.aws/

The jovo.project.js also includes the permissions to create and update a DynamoDb table. By default, the table will be called jovo-sample-db. You can also update it in the project config under the prod stage:

new ServerlessCli({
  provider: {
    // ...
    environment: {
      DYNAMODB_TABLE_NAME: 'jovo-sample-db',
    },
  },
  // ...
}),

On the first request, the Lambda will fail because of the DynamoDb table creation. On the next request, the table should be created and everything should work correctly.

Next Steps

Learn more about the Jovo app project structure and key concepts in the Jovo getting started docs.

You might also like...

Find a local sport match that fits your skill level. Built with NextJS and AWS.

MatchUp This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open

Oct 27, 2022

Find a local sports match that fits your skill level. Built with NextJS and AWS.

Find a local sports match that fits your skill level. Built with NextJS and AWS.

MatchUp MatchUp Find local sport matches Beta walkthrough About The Project Looking for a fun and easy way to meet up and play sports with locals in y

Oct 27, 2022

Learn Web 2.0 and Web 3.0 Development using Next.js, Typescript, AWS CDK, AWS Serverless, Ethereum and AWS Aurora Serverless

Learn Web 2.0 Cloud and Web 3.0 Development in Baby Steps In this course repo we will learn Web 2.0 cloud development using the latest state of the ar

Jan 3, 2023

Sample code for resizing Images with Lambda@Edge using the Custom Origin. You can deploy using AWS CDK.

Sample code for resizing Images with Lambda@Edge using the Custom Origin. You can deploy using AWS CDK.

Resizing Images with Lambda@Edge using the Custom Origin You can resize the images and convert the image format by query parameters. This Lambda@Edge

Dec 11, 2022

Implementing hexagonal architecture on AWS Lambda with Node.js

Implementing hexagonal architecture on AWS Lambda with Node.js

Developing evolutionary architecture with AWS Lambda Context Agility enables you to evolve a workload quickly, adding new features, or introducing new

Dec 20, 2022

AWS Lambda and API Gateway, simplified for Javascript

AWS Lambda and API Gateway, simplified for Javascript

alanajs AWS Lambda and API Gateway, simplified for JavaScript About alanajs Make setting up Lambda microservices easier than ever. alanajs is a free,

Aug 1, 2022

A simple example repo that demonstrates the dynamic ephemeral storage solution for AWS Lambda outlined in the corresponding Storyboard Dev Blog post.

AWS Lambda Dynamic Ephemeral Storage Example A simple example repo that demonstrates the dynamic ephemeral storage solution for AWS Lambda outlined in

Jun 14, 2022

🚀 Using top-level await in AWS Lambda with TypeScript, esbuild and Serverless Framework

🚀 Using top-level await in AWS Lambda with TypeScript, esbuild and Serverless Framework

🚀 Top-level await in AWS Lamba with TypeScript Articles https://dev.to/oieduardorabelo/top-level-await-in-aws-lamba-with-typescript-1bf0 https://medi

Nov 23, 2022

Google-Drive-Directory-Index | Combining the power of Cloudflare Workers and Google Drive API will allow you to index your Google Drive files on the browser.

🍿 Google-Drive-Directory-Index Combining the power of Cloudflare Workers and Google Drive will allow you to index your Google Drive files on the brow

Jan 2, 2023
Owner
Jovo
Build cross-platform apps for voice and beyond.
Jovo
MerLoc is a live AWS Lambda function development and debugging tool. MerLoc allows you to run AWS Lambda functions on your local while they are still part of a flow in the AWS cloud remote.

MerLoc MerLoc is a live AWS Lambda function development and debugging tool. MerLoc allows you to run AWS Lambda functions on your local while they are

Thundra 165 Dec 21, 2022
AWS Lambda & Serverless - Developer Guide with Hands-on Labs. Develop thousands line of aws lambda functions interact to aws serverless services with real-world hands-on labs

AWS Lambda & Serverless - Developer Guide with Hands-on Labs UDEMY COURSE WITH DISCOUNTED - Step by Step Development of this Repository -> https://www

awsrun 35 Dec 17, 2022
A sample CICD Deployment Pipeline for your Alexa Skills, using AWS CDK, CodeBuild and CodePipeline

Alexa Skils - CI/CD CDK Pipeline This repository will help you setting up a CI/CD pipeline for your Alexa Skills. This pipeline is powered by AWS Clou

null 5 Nov 23, 2022
Under the Sea is an official AWS workshop delivered by AWS SAs and AWS Partners to help customers and partners to learn about AIOps with serverless architectures on AWS.

Under the Sea - AIOps with Serverless Workshop Under the Sea is an exciting MMORPG developed by the famous entrepreneur behind Wild Rydes, the most po

AWS Samples 4 Nov 16, 2022
A serverless AWS expense tracker API. AWS Lambda functions, API gateway, and Dynamodb are among the ingredients.

AWS-Serverless-API A serverless AWS expense tracker API. AWS Lambda functions API gateway Dynamodb Endpoints Create a new expense: Method: POST Body f

Ondiek Elijah Ochieng 1 Jul 16, 2022
Everynode allows you to run any version of Node.js in AWS Lambda, in any commercial AWS region

Run Any Node.js Version in AWS Lambda Everynode allows you to run any version of Node.js in AWS Lambda, in any commercial AWS region. We add support f

Fusebit 116 Dec 15, 2022
A monorepo that uses the AWS Cloud Development Kit to deploy and configure nanomdm on AWS lambda.

NanoMDM on AWS This repo builds and configures a nanomdm server to run on AWS lambda. It uses the Cloud Development Kit and tries to follow best pract

Stevie Clifton 4 May 26, 2022
Lumos is an AWS Lambda visualizer and open source alternative to AWS CloudWatch.

Lumos Lambda Metrics Visualizer Table of Contents About Lumos Techologies Used Getting Started Key Lambda Metrics How to Contribute License Contributo

OSLabs Beta 36 Nov 5, 2022
A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM deffiniation and appropriate file structure.

Welcome to function-stencil ?? A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM

Ben Smith 21 Jun 20, 2022