An Amazon Lambda Deployment Workflow for Alexa Skills

DZone 's Guide to

An Amazon Lambda Deployment Workflow for Alexa Skills

If you're working on Alexa skills, the workflow might not be intuitive. This one helps AWS Lambda keep up to date with your code so you can edit locally, then deploy.

· IoT Zone ·
Free Resource

I mentioned in my post about creating a new skill for Alexa that I found the workflow quite clunky. Having tried a bit more and bugged a few people to find out how they hadn't killed anyone trying to develop with a workflow like this, I have some tips to share!

Set Up an Alias

One thing I really struggled with was the fact that you can't set a trigger on the current version of a Lambda function that you're editing through the web interface (called $LATEST). However, it turns out that you can create an alias that points to $LATEST rather than a specific version number, so the alias will always be whatever version you're on.

Now go ahead and create a trigger for your Lambda function, which is the "Alexa Skills Kit." With this in place, you can create (or edit) an Alexa skill through the Alexa Developer Console and configure the location of the function to the ARN, including the alias you created (mine is called "prod").

At this point, you can create and publish new versions of code without having to recreate the trigger and update the skill itself, progress!

Edit Code Locally, Then Deploy

Editing code in a web interface is never a good way to do anything more than a trivial example and especially for this vim user, it got very tedious very fast! It's possible to deploy code to Amazon Lambda by zipping up your file, putting it onto Amazon's S3 storage platform, and then making an API call to notify Lambda to pick up the new version - which is to say, that this is all scriptable!

To get this to work, you'll need Amazon's CLI tool installed on your machine (or wherever you want to deploy code from — it would also make a lot of sense on a build server). Get that installed and check it with aws --version, which should give you some sane output.

Next, you need a script that will:

  1. Create a ZIP file containing the `index.js` file that your function lives in.
  2. Upload the ZIP file to S3.
  3. Get Lambda to use the new code.

My script looks like this:


rm -f lorna.zip
cd src
zip ../lorna.zip index.js
cd ..

aws s3 cp lorna.zip s3://alexa-lorna/
aws lambda update-function-code --function-name AlexaPing --s3-bucket alexa-lorna --s3-key lorna.zip

This just deletes the previous ZIP file (you could delete it at the end of the script but not clearing up build artifacts makes debugging easier!), creates a new one from the directory level that the ZIP file should unzip its paths relative to, and puts the index.js into it. We upload to an s3 bucket called alex-alorna. Finally, there's a command to tell Lambda to use the new code for the function named AlexaPing and which file to use.

With all this in place, I can edit locally (you could rig up a little hacky script to call it locally as well) and then run the script above to deploy the new version. Hopefully one or more of the ingredients here will prove useful to someone in the future, it definitely felt harder to figure out than it needed to be!

alexa skills ,iot app development ,cli ,aws lambda ,iot ,tutorial

Published at DZone with permission of Lorna Mitchell , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}