Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
115 lines (99 sloc) 3.93 KB

Actions

Setting values from environment variables

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.

Manifest File

Example: “Hello world” with input values set from environment variables

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}

Deploying

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

Invoking

$ wsk action invoke hello_world_package/hello_world_env_var_parms --blocking

Result

The invocation should return an 'ok' with a response that includes this result:

"result": {
   "greeting": "Hello, Sam from the Shire, Middle-earth"
},

Invoking

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

Result

the result will reflect the changes to the environment variables:

"result": {
   "greeting": "Hello, Elrond from Rivendell, M.E."
},

Discussion

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

Notes:

  • These methods for binidng environment variables to input parameters are also available within Deployment files.

Source code

The manifest file for this example can be found here:

Specification

For convenience, the Actions and Parameters grammar can be found here:


You can’t perform that action at this time.