Deploying OpenWhisk Actions With Dependencies

I mostly use OpenWhisk with NodeJS (which is lucky for me, it’s the best supported of the languages and default for the documentation examples!) and while there are a bunch of npm modules already installed on OpenWhisk, sometimes there will be others that you also want to include. Alternatively or additionally, you might also want to deploy your package.json since this can specify the entry point if it’s not index.js which is the default.

To include the dependencies, you should set up your project as usual and run npm install on your local machine. Then, zip up your JavaScript file(s), and the node_modules folder, plus package.json if you need it – and deploy those as your action. Here’s a script I use to do this in one of my own projects (the Project Codename generator I built as an Alexa skill):

zip -r index.js node_modules

wsk action update --kind nodejs:6 alexa/project-codename

The first line creates the zip file and the second one uses it to update (or create if it doesn’t exist) my action. It’s a simple workflow but like so many things – easy when you know how. I had to ask for someone else’s example and hopefully by sharing this, I’ve enabled someone else and so we keep on building more awesome :)

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.