As with most language introductions, in this first example we encode a simple "hello world" action, written in JavaScript, using an OpenWhisk Package Manifest YAML file.
It shows how to:
- declare a single Action named ‘hello_world’ within the ‘hello_world_package’ Package.
- associate the JavaScript function’s source code, stored in the file ‘src/hello.js’, to the ‘hello_world’ Action.
packages:
hello_world_package:
version: 1.0
license: Apache-2.0
actions:
hello_world:
function: src/hello.js
where "hello.js", within the package-relative subdirectory named ‘src’, contains the following JavaScript code:
function main(params) {
msg = "Hello, " + params.name + " from " + params.place;
return { greeting: msg };
}
You can actually deploy the "hello world" manifest from the openwhisk-wskdeploy project directory if you have downloaded it from GitHub:
$ wskdeploy -m docs/examples/manifest_hello_world.yaml
$ wsk action invoke hello_world_package/hello_world --blocking
The invocation should return an 'ok' with a response that includes this result:
"result": {
"greeting": "Hello, undefined from undefined"
},
The output parameter 'greeting
' contains "undefined" values for the 'name
' and 'place
' input parameters as they were not provided in the manifest.
This "hello world" example represents the minimum valid Manifest file which includes only the required parts of the Package and Action descriptors.
In the above example,
- The Package and its Action were deployed to the user’s default namespace using the ‘package’ and 'action' names from the manifest.
/<default namespace>/hello_world_package/hello_world
- The NodeJS default runtime (i.e.,
runtime: nodejs
) was selected automatically based upon the file extension '.js
'' of the function's source file 'hello.js
'.
The source code for the manifest and JavaScript files can be found here:
For convenience, the Packages and Actions grammar can be found here: