Coming soon! Apache APISIX Integrate with Apache OpenWhisk

Apache APISIX
Apache OpenWhisk
Published in
4 min readDec 30, 2021

In this article, we will introduce openwhisk, a new plug-in for Apache APISIX, and show you how to integrate OpenWhisk service with Apache APISIX to enjoy the benefits of serverless computing with detailed steps. This plugin is expected to go live in Apache APISIX 2.12, so stay tuned!

Project Introduction

Apache APISIX

Apache APISIX is a dynamic, real-time, high-performance API gateway that provides rich traffic management features such as load balancing, dynamic upstream, grayscale publishing, service fusion, authentication, observability, etc. Apache APISIX not only supports plug-in dynamic changes and hot-plugging, but also has many useful plug-ins.

Apache OpenWhisk

Apache OpenWhisk is an open source distributed serverless platform that can execute serverless functions on demand and at scale. It uses Docker containers to manage infrastructure, servers, and scales to help users build great and efficient applications.

Developers can use multiple programming languages to write functions (called Actions) that will be dynamically dispatched and processed by OpenWhisk in response to events (via triggers) or external requests (via HTTP requests).

Integration Principle

Apache APISIX provides plug-in support for easy integration with Apache OpenWhisk. Users can define a route that includes a serverless plug-in and combine it with various authentication plug-ins provided by Apache APISIX to implement authentication and authorization functions.

The general principle of operation is as follows: users can use the openwhisk plugin to define a "dynamic upstream" in the route, and when the route matches a request, it will abort the request to the original upstream and send a request to the API Host endpoint of OpenWhisk.

The request will contain the Namespace, Action, Service Token and raw HTTP request body data configured by the user for the plugin, and will return the response content obtained from OpenWhisk to the client.

How to use

Step 1: Set up Apache OpenWhisk test environment

First, you need to ensure that you are using a Linux system with Docker software installed on it. Execute the following command.

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:nightlydocker exec openwhisk waitready

Wait for the command execution to complete and the following will be output.

ok: whisk auth set. Run 'wsk property get --auth' to see the new value.ok: whisk API host set to http://openwhisk:3233ok: updated action testmeserver initializing...server initializing...    "ready": trueok: deleted action testme

Create the following file test.js to be used as a test function.

function main(args) {    return {        "hello": args.name || "",    };}

Register the above functions in OpenWhisk.

# Set API Host and authentication information for the OpenWhisk CLI tool,you can download from https://s.apache.org/openwhisk-cli-downloadwsk property set \  --apihost 'http://localhost:3233' \  --auth '23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP'# Create a test functionwsk action create test test.js

Step 2: Create a route and enable OpenWhisk plugin

Next we will create a route and add the openwhisk plugin to it. Execute the following command.

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

Step 3: Testing the request

In the following we will use cURL for testing.

# Request and send data using POSTcurl http://127.0.0.1:9080/openwhisk -i -X POST -d '{"name": "world"}'HTTP/1.1 200 OKContent-Type: application/jsonContent-Length: 17Server: APISIX/2.10.2{"hello":"world"}# Request using GETcurl http://127.0.0.1:9080/openwhisk -iHTTP/1.1 200 OKContent-Type: application/jsonContent-Length: 12Server: APISIX/2.10.2{"hello":""}

Step 4: Test complex responses

Create and update the test.js test function

function main(args) {    return {        "status": "403",        "headers": {        "test": "header"    },        "body": "A test body"    };}

Conduct the test requests.

# Request using GETcurl http://127.0.0.1:9080/openwhisk -iHTTP/1.1 403 FORBIDDENContent-Type: application/jsonContent-Length: 12test: headerServer: APISIX/2.10.2A test body

Turn off the plugin

If you are done using the OpenWhisk plug-in, simply remove the OpenWhisk-related configuration from the route configuration and save it to close the OpenWhisk plug-in on the route. At this point you can open other Serverless-like plug-ins or add upstream and other subsequent operations.

Thanks to the dynamic advantage of Apache APISIX, the process of turning on and off plug-ins does not require restarting Apache APISIX, which is very convenient.

Summary

In this article, we have introduced the feature preview and usage steps of openwhisk plugin. For more information about openwhisk plugin description and full configuration list, please refer to the official documentation.

If you’re interested in such integration projects, feel free to start a discussion in GitHub Discussions or communicate via the mailing list.

--

--

Apache APISIX
Apache OpenWhisk

Apache APISIX is a Cloud-Native Microservices API Gateway