Package Parameters in OpenWhisk

I love OpenWhisk but I struggled a little to get the parameters attached in a sane way for a while so I am capturing my notes here for future reference! Parameters can be attached to actions or packages; I tend to break my actions down really small and pass data into them, while preferring to set parameters on the package that the actions belong to.

You can set parameters on the commandline individually, like this:

wsk package update mypackage -p dbname awesomedb

This gets clunky once you have a few parameters, and you can’t add new parameters, whatever you use here will remove any previous params and overwrite. Instead I like to hold the parameters in a file, and edit it and update the action as needed.

Pro tip: you probably don’t want to store the parameters file in source control! Feed it to your deployment toolchain.

Parameters files should be formatted something like this (it’s JSON)

"slackURL": "",
"cloudantURL": "",
"dbname": "awesomedb"

Then to supply this file (called params.json) to the package:

wsk package update mypackage -P params.json

(that’s an uppercase P not the lowercase one as in the earlier example)

You can use this approach to more easily repeat existing parameters, and just add/change what you need to.

Pro-tip: wondering what parameters are already set on this package? Use wsk package get mypackage parameters to see :)

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.