Actions

Setting your Function's runtime

In the previous “Hello world” example, the wskdeploy utility used the file extension of the function “hello.js” to select the most current NodeJS runtime.

In most cases, allowing the utility to select the runtime works well using this implicit method. However, perhaps your code is dependent on a specific version of a language runtime and you want to explicitly set it?

This example shows how to:

  • declare an explicit runtime for your Action's function.

Manifest file

Example: explicit selection of the NodeJS version 10 runtime

packages:
  hello_world_package:
    version: 1.0
    license: Apache-2.0
    actions:
      hello_world_runtime:
        function: src/hello.js
        runtime: nodejs@10

Deploying

$ wskdeploy -m docs/examples/manifest_hello_world_runtime.yaml

Invoking

$ wsk action invoke hello_world_package/hello_world_runtime --blocking

Result

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

"result": {
    "greeting": "Hello, undefined from undefined"
},

Discussion

In the above example,

  • The value for the ‘runtime’ key was a valid name and version supported by OpenWhisk

Runtime mismatch for function

If the language runtime you requested is not compatible with the function's language, then you will receive an error response when invoking the Action. For example, the following manifest indicates a JavaScript (.js) function, but the runtime selected as “python”:

package:
  name: hello_world_package
  ...
  actions:
    hello_world_runtime:
      function: src/hello.js
      runtime: python

The result would a “failure” with a failed response:

"response": {
    "result": {
        "error": "The action failed to generate or locate a binary. See logs for details."
    },
    "status": "action developer error",
    "success": false

Source code

The source code for the manifest and JavaScript files can be found here:

Specification

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

Notes

  • If you use the following curl command, you can see the latest runtimes and version supported by the target OpenWhisk platform:
    • curl -k <OpenWhisk API_HOST>

      • Simply replace the API Host value with the API endpoint address for your provider's OpenWhisk platform.
    • For example, you can test this against the IBM Cloud Functions platform:

      • curl -k https://openwhisk.ng.bluemix.net