Skip to main content
Version: 3.7

openwhisk

Description#

The openwhisk Plugin is used to integrate APISIX with Apache OpenWhisk serverless platform.

This Plugin can be configured on a Route and requests will be send to the configured OpenWhish API endpoint as the upstream.

Attributes#

NameTypeRequiredDefaultValid valuesDescription
api_hoststringTrueOpenWhisk API host address. For example, https://localhost:3233.
ssl_verifybooleanFalsetrueWhen set to true verifies the SSL certificate.
service_tokenstringTrueOpenWhisk service token. The format is xxx:xxx and it is passed through basic auth when calling the API.
namespacestringTrueOpenWhisk namespace. For example guest.
actionstringTrueOpenWhisk action. For example hello.
resultbooleanFalsetrueWhen set to true gets the action metadata (executes the function and gets response).
timeoutintegerFalse60000ms[1, 60000]msOpenWhisk action and HTTP call timeout in ms.
keepalivebooleanFalsetrueWhen set to true keeps the connection alive for reuse.
keepalive_timeoutintegerFalse60000ms[1000,...]msTime is ms for connection to remain idle without closing.
keepalive_poolintegerFalse5[1,...]Maximum number of requests that can be sent on this connection before closing it.
note

The timeout attribute sets the time taken by the OpenWhisk action to execute, and the timeout for the HTTP client in APISIX. OpenWhisk action calls may take time to pull the runtime image and start the container. So, if the value is set too small, it may cause a large number of requests to fail.

OpenWhisk supports timeouts in the range 1ms to 60000ms and it is recommended to set it to at least 1000ms.

Enable Plugin#

Before configuring the Plugin, you need to have OpenWhisk running. The example below shows OpenWhisk in standalone mode:

docker run --rm -d \
-h openwhisk --name openwhisk \
-p 3233:3233 -p 3232:3232 \
-v /var/run/docker.sock:/var/run/docker.sock \
openwhisk/standalone:nightly
docker exec openwhisk waitready

Install the openwhisk-cli utility.

You can download the released executable binaries wsk for Linux systems from the openwhisk-cli repository.

You can then create an action to test:

wsk property set --apihost "http://localhost:3233" --auth "23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP"
wsk action update test <(echo 'function main(){return {"ready":true}}') --kind nodejs:14

You can now configure the Plugin on a specific Route and point to this running OpenWhisk service:

curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/hello",
"plugins": {
"openwhisk": {
"api_host": "http://localhost:3233",
"service_token": "23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP",
"namespace": "guest",
"action": "test"
}
}
}'

Example usage#

Once you have configured the Plugin, you can send a request to the Route and it will invoke the configured action:

curl -i http://127.0.0.1:9080/hello

This will give back the response from the action:

{ "ready": true }

Delete Plugin#

To remove the openwhisk Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect.

curl http://127.0.0.1:9180/apisix/admin/routes/1  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"methods": ["GET"],
"uri": "/index.html",
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
}
}'