This example shows how to set input parameter values using environment variables. “hello world” example and shows how fixed values can be supplied to the input parameters of an Action.
It shows how to:
- declare input parameters on the action ‘
hello_world
’ whose values are set (i.e., bound) from values taken from environment variables.- using both single-line and multi-line grammars.
- concatenate string parameter values with values provided from environment variables.
- use this feature using both single-line and multi-line grammars.
packages:
hello_world_package:
version: 1.0
license: Apache-2.0
actions:
hello_world_env_var_parms:
function: src/hello.js
inputs:
name: $FIRSTNAME
place: ${TOWN}, ${COUNTRY}
Set the values for the three environment variables expected by the Action and deploy:
$ FIRSTNAME=Sam TOWN="the Shire" COUNTRY="Middle-earth" wskdeploy -m docs/examples/manifest_hello_world_env_var_parms.yaml
$ wsk action invoke hello_world_package/hello_world_env_var_parms --blocking
The invocation should return an 'ok' with a response that includes this result:
"result": {
"greeting": "Hello, Sam from the Shire, Middle-earth"
},
if we modify the three environment variables to different values, update the action and invoke it again:
$ export FIRSTNAME=Elrond TOWN="Rivendell" COUNTRY="M.E."
$ wskdeploy -m docs/examples/manifest_hello_world_env_var_parms.yaml
$ wsk action invoke hello_world_package/hello_world_env_var_parms --blocking
the result will reflect the changes to the environment variables:
"result": {
"greeting": "Hello, Elrond from Rivendell, M.E."
},
In this example:
- it was shown how values provided by environment variables, within the execution of the wskdeploy utility, could be bound to input parameter values within a Manifest file.
- we further demonstrated how string values from environment variables could be concatenated with other strings within a Manifest file
- These methods for binding environment variables to input parameters are also available within Deployment files.
The manifest file for this example can be found here:
For convenience, the Actions and Parameters grammar can be found here: