Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Package Parameters in OpenWhisk

DZone's Guide to

Package Parameters in OpenWhisk

Attaching OpenWhisk parameters to packages can be tricky, and setting parameters on individually on the command line can get clunky fast. Put them in a file instead.

· Cloud Zone ·
Free Resource

Insight into the right steps to take for migrating workloads to public cloud and successfully reducing cost as a result. Read the Guide.

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 command line 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": "https://hooks.slack.com/services/blah/blah",
    "cloudantURL": "https://wibble-squeak-bluemix.cloudant.com",
    "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!

TrueSight Cloud Cost Control provides visibility and control over multi-cloud costs including AWS, Azure, Google Cloud, and others.

Topics:
cloud ,openwhisk ,serverless platforms ,parameters ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}