This plugin is not compatible with Konnect
This plugin invokes OpenWhisk Action. The Apache OpenWhisk plugin can be used in combination with other request plugins to secure, manage, or extend the function.
Installation
This plugin is not bundled with Kong Gateway.
You can either use the LuaRocks package manager to install the plugin:
luarocks install kong-plugin-openwhisk
Or install it from source. For more information on plugin installation, see the documentation Plugin Development - (un)Install your plugin.
Demonstration
For this demonstration, we are running Kong and Openwhisk platform locally on a Vagrant machine on a MacOS.
Step 1. Create a JavaScript Action
Create a JavaScript Action hello
with the following code snippet on the
Openwhisk platform using wsk cli
.
function main(params) {
var name = params.name || 'World';
return {payload: 'Hello, ' + name + '!'};
}
wsk action create hello hello.js
ok: created action hello
Step 2. Create a service or route
Step 3. Enable the openwhisk
plugin on the route
Note: If
config.https_verify
is set totrue
, then the server certificate is verified according to the CA certificates specified by thelua_ssl_trusted_certificate
directive in your Kong configuration.
Step 4. Make a request to invoke the action
Without parameters:
curl -i -X POST http://localhost:8000/ -H "Host:example.com"
Response:
HTTP/1.1 200 OK
...
{
"payload": "Hello, World!"
}
Parameters as form-urlencoded:
curl -i -X POST http://localhost:8000/ -H "Host:example.com" --data "name=bar"
Response:
HTTP/1.1 200 OK
...
{
"payload": "Hello, bar!"
}
Parameters as JSON body:
curl -i -X POST http://localhost:8000/ -H "Host:example.com" \
-H "Content-Type:application/json" --data '{"name":"bar"}'
Response:
HTTP/1.1 200 OK
...
{
"payload": "Hello, bar!"
}
Parameters as multipart form:
curl -i -X POST http://localhost:8000/ -H "Host:example.com" -F name=bar
Response:
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
...
{
"payload": "Hello, bar!"
}
Parameters as querystring:
curl -i -X POST http://localhost:8000/?name=foo -H "Host:example.com"
Response:
HTTP/1.1 200 OK
...
{
"payload": "Hello, foo!"
}
OpenWhisk metadata in response:
When Kong’s config.result
is set to false
, OpenWhisk’s metadata is
returned in the response.
curl -i -X POST http://localhost:8000/?name=foo -H "Host:example.com"
Response:
HTTP/1.1 200 OK
...
{
"duration": 4,
"name": "hello",
"subject": "guest",
"activationId": "50218ff03f494f62abbde5dfd2fcc68a",
"publish": false,
"annotations": [{
"key": "limits",
"value": {
"timeout": 60000,
"memory": 256,
"logs": 10
}
}, {
"key": "path",
"value": "guest/hello"
}],
"version": "0.0.4",
"response": {
"result": {
"payload": "Hello, foo!"
},
"success": true,
"status": "success"
},
"end": 1491855076125,
"logs": [],
"start": 1491855076121,
"namespace": "guest"
}
Limitations
Use a fake upstream service
When using the OpenWhisk plugin, the response is returned by the plugin
itself without proxying the request to any upstream service. This means that
a Service’s host
, port
, path
properties are ignored, but must still
be specified for the entity to be validated by Kong. The host
property in
particular must either be an IP address, or a hostname that gets resolved by
your nameserver.
Response plugins
There is a known limitation in the system that prevents some response plugins from being executed. We are planning to remove this limitation in the future.