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: https://console.aws.amazon.com/iam
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
AWS Access Key ID:  ACCESS_KEY_ID
AWS Secret Access Key: SECRET_ACCESS_KEY
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:

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

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

Notes

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.