Skip to content

Latest commit

 

History

History
130 lines (103 loc) · 5.88 KB

openwhisk.md

File metadata and controls

130 lines (103 loc) · 5.88 KB
title keywords description
openwhisk
APISIX
Plugin
OpenWhisk
openwhisk
This document contains information about the Apache openwhisk Plugin.

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

Name Type Required Default Valid values Description
api_host string True OpenWhisk API host address. For example, https://localhost:3233.
ssl_verify boolean False true When set to true verifies the SSL certificate.
service_token string True OpenWhisk service token. The format is xxx:xxx and it is passed through basic auth when calling the API.
namespace string True OpenWhisk namespace. For example guest.
action string True OpenWhisk action. For example hello.
result boolean False true When set to true gets the action metadata (executes the function and gets response).
timeout integer False 60000ms [1, 60000]ms OpenWhisk action and HTTP call timeout in ms.
keepalive boolean False true When set to true keeps the connection alive for reuse.
keepalive_timeout integer False 60000ms [1000,...]ms Time is ms for connection to remain idle without closing.
keepalive_pool integer False 5 [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.

:::

Enabling the 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: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"
        }
    }
}'

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 }

Disable Plugin

To disable 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:9080/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
        }
    }
}'