Apache OpenWhisk + The Serverless Framework: PHP Support, Docker runtime and more…

Apache OpenWhisk and The Serverless Framework

There is a new release (0.9.0) of the Apache OpenWhisk provider plugin for The Serverless Framework.

Combined with the latest release of The Serverless Framework (0.21), this update adds PHP runtime support, custom Docker runtime integration, optional parameters for Cloudant events and more…

Want to get started?

Have you already got the framework and provider plugin installed? Update both packages to the latest versions.

$ npm update -g serverless serverless-openwhisk

Otherwise, install both modules as global packages.

$ npm install -g serverless serverless-openwhisk

The Serverless Framework website has documentation on using the framework with Apache OpenWhisk. Looking for working samples? There are numerous projects into this “examples” repository.

So, what’s new in the Apache OpenWhisk provider plugin?

PHP Support

Apache OpenWhisk now supports the PHP runtime. Handler functions are called with a single argument, an associative array containing the request properties. Associative arrays must be returned as the response.

function main(array $args) : array
$name = $args["name"] ?? "stranger";
$greeting = "Hello $name!";
echo $greeting;
return ["greeting" => $greeting];

The Serverless Framework has been updated to support the php runtime.

handler: index.main
runtime: php

The create plugin supports a new template for this runtime: openwhisk-php

$ serverless create --template openwhisk-php 
$ tree .
├── README.md
├── handler.php
├── package.json
└── serverless.yml
0 directories, 4 files

The serverless.yaml configures a single “Hello World” function.

service: my_service
name: openwhisk
runtime: php
handler: handler.hello

The handler.php file contains the function handler (hello) to be called for invocations.

This boilerplate application can be deployed without modification.

Remember tonpm install project dependencies before running serverless deploy.

$ npm install
$ serverless deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Compiling Functions...
Serverless: Compiling API Gateway definitions...
Serverless: Compiling Rules...
Serverless: Compiling Triggers & Feeds...
Serverless: Deploying Functions...
Serverless: Deployment successful!

Invoke the hello function to test it works once deployed.

$ serverless invoke -f hello
"greeting": "Hello stranger!"

Custom Docker Runtimes

OpenWhisk recently extended Docker integration to support using custom images with private deployment archives. This allows developers to use extra libraries, dependencies or other tools larger than the deployment archive limit (48MB).

Custom images can now be specified using the image property in serverless.yaml

service: my_service
name: openwhisk
runtime: python
handler: handler.hello

Functions will be executed in a container from the image specified, rather than the default platform runtime image. Deployment archives will still be created for the language specified by the runtime property.

Node.js, Swift, Python and Binary runtimes support using a custom image property.

Optional Cloudant Event Parameters

Cloudant uses CouchDB’s changes feed to follow modifications to the document database.

The feed provider now supports filtering the event stream using a custom function. This allows users to control which events invoke the OpenWhisk trigger.

Setting the filter and query parameters in serverless.yaml will now configure event filtering support.

The Cloudant event provider has also added a new max property to set the maximum number of events to fire.

handler: users.main
- cloudant:
max: 10000 // max triggers
query: // filter parameters
status: new
filter: mailbox/by_status

Apache OpenWhisk was the first serverless platform to integrate into The Serverless Framework after AWS Lambda. The provider plugin will continue to be updated as the platform adds new features. Follow the milestone plan for updates on future releases.

Found bugs in the plugin? Ideas for new feature? Any other comments or feedback?

Please open issues on Github: https://github.com/serverless/serverless-openwhisk/issues