Skip to main content
Version: 2.14

openwhisk

Description#

The openwhisk plugin is used to support integration with the Apache OpenWhisk serverless platform and can be set up on a route in place of Upstream, which will take over the request and send it to the OpenWhisk API endpoint.

Users can call the OpenWhisk action via APISIX, pass the request parameters via JSON and get the response content.

Attributes#

NameTypeRequirementDefaultValidDescription
api_hoststringrequired  OpenWhisk API host (eg. https://localhost:3233)
ssl_verifybooleanoptionaltrueWhether to verify the certificate
service_tokenstringrequired  OpenWhisk ServiceToken (The format is xxx:xxx,Passed through Basic Auth when calling the API)
namespacestringrequired  OpenWhisk Namespace (eg. guest)
actionstringrequired  OpenWhisk Action (eg. hello)
resultbooleanoptionaltrue Whether to get Action metadata (default to execute function and get response; false to get Action metadata but not execute Action, including runtime, function body, restrictions, etc.)
timeoutintegeroptional60000ms[1, 60000]msOpenWhisk Action and HTTP call timeout.
keepalivebooleanoptionaltrue HTTP keepalive
keepalive_timeoutintegeroptional60000ms [1000,...]keepalive idle timeout
keepalive_poolintegeroptional5[1,...]Connection pool limit
note
  • The timeout property controls both the time taken by the OpenWhisk Action to execute and the timeout of the HTTP client in APISIX. OpenWhisk Action calls may consume time on pulling the runtime image and starting the container, so if you set the value too small, you may cause a large number of requests to fail. OpenWhisk supports timeouts ranging from 1ms to 60000ms, and we recommended to set at least 1000ms or more.

Example#

First, you need to run the OpenWhisk environment. Here is an example of using OpenWhisk 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

Then, you need to create an Action for testing.

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

Here is an example of creating a Route and enabling this plugin

curl http://127.0.0.1:9080/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"
}
}
}'

Finally, you can send a request to this route and you will get the following response. And you can disable it by removing the openwhsik plugin from the route.

{"ready": true}