Saturday 8 July 2017

Setting up a Local Alexa Development Environment

This blog entry shows how to set up a local development environment for the Amazon Echo.  It doesn't provide information on how to write echo skills (that's reserved for other blog entries!).

This assumes that you've already got an echo, and have already got an Amazon account set up.

Download the System Tools (Ubuntu Shown)
$ sudo apt-get nodejs npm python
$ pip install --upgrade aws
$ pip install --upgrade awscli
$ sudo npm install -g lambda-local aws-lambda nodejs
Set Up an access key Pair

Log into the Amazon Console using your amazon account:
Expand the first entry (regarding root keys), and select Manage Security Credentials.
In the Security Credentials, Create a New Access Key.

Either download the access key information, or leave this dialog box open so hat you can use the information later.

Note that you don't need to create any Keys (other parts of the IAM security pages).  Creating other keys will cause you to be invoiced for them!!!

Configure the tools for the User

Configure your AWS environment, using the access key and secret you previously created in the IAM console online.
$ aws configure
Default region name: eu-west-1
Default output format [None]: 
You can now Upload Lambda Applications

Creating a lambda-local application environment

Create an alexa subdirectory, and in it, create the following folders:
  • assets - This is where the images and utterances will go (used in the launching and publication of your skill)
  • bin - This is where your utilities / applications will go
  • dist - This is where your distribution snapshots will go
  • js - This is where your javascript will go
  • test - This is where your test json input files will go
In the bin folder, create three scripts:

cd "`dirname $0`/../js"
MODULES="`grep require *.js | grep -v \\./ | sed -e s/\\"/\\'/g | cut -d\\' -f2`"
npm install $MODULES --save
echo "Installed: $MODULES"
cd `dirname $0`/..
if [ -z $1 ]; then
  cd test
  echo "Usage: test event"
  echo "Valid Events: `ls *.json | sed -e 's/.json//g'`"
lambda-local -p ~/.aws/credentials -l js -e "test/$1.json"
cd `dirname $0`/..
APPNAME="`basename $HOMEDIR`"
DATE="`date +%y%m%d%H%M%S`"
cd js
zip -r ../dist/$APPNAME-$ . > /dev/null
cd ../dist
rm -f $
ln -s $APPNAME-$ $
aws lambda update-function-code --function-name $APPNAME --zip-file fileb://$

You can now create your files in the js folder
run them with the test command
And upload the project to run on the alexa with the upload command


Make sure your test json files have a userId defined, otherwise scripts that use dynamoDB will fail to run, because your scripts will use the access key to access your online dynamoDB database.

If you get errors when running the upload script, that state that 'aws lambda' is not recognised, it is possible that you've got an old version of the aws program installed.  Try 'aws -v' or 'aws --version'.  Places to look are /usr/local/bin and /usr/bin.

No comments:

Post a Comment