One of the cool things about OpenWhisk was the ability to start a local copy and get coding very quickly. James Thomas has an awesome post on this — Starting OpenWhisk in Sixty Seconds. This also enabled developers to create and test their Serverless solutions on their machines. The amazing OpenWhisk community have taken this one step further. Chetan Mehrotra recently added code to enable running OpenWhisk as a standalone jar! How cool is that!
At a high level, they have taken out CouchDB and Kafka and replaced them with in memory persistence layer and a queueing system. The controller and invoker have also been slimmed down. There is obviously more to it and is well captured in the following links.
- https://github.com/apache/openwhisk/pull/4516
- https://github.com/apache/openwhisk/pull/4216
- https://lists.apache.org/thread.html/7425131f1fc11a9fd21e9c049be702837841c47004da03b7f215a0d6@%3Cdev.openwhisk.apache.org%3E
So how do you get started?
Step 1: Build the jar file
- You can build it yourself by following the steps in the official repo. The final jar will be available in the /bin folder. This is the preferable approach as you always get the latest features
- Alternatively, if you must insist, you can download the pre-built jar file from here. I am not sure if this will be kept up to date. So try at your own risk!
Step 2: run the jar file
Once you have the jar file, you can run it as follows
java -jar bin/openwhisk-standalone.jar
There are numerous other options available, but this will suffice for now. That’s it! You have a Serverless platform running on your local machine. You can run all your favorite wsk commands just as your would with a production level distributed OpenWhisk installation!
Step 3: create and deploy a simple action
If you have never deployed an action on Apache OpenWhisk or IBM Cloud, you can follow these steps
3.1 Download the wsk cli.
3.2 Create your function
function main(args) {
if (args && args.name) {
console.log(`hello ${args.name}`);
return { msg: `hello ${args.name}` };
} else {
console.log(`hello world`);
return { msg: `hello world` };
}
}
3.3 Before you deploy your function/action, you need to set the auth property using the wsk cli. This command was provided to you when you started the jar file. Simply copy paste in terminal!
- That’s it! Let’s deploy the index.js file as an action
$ wsk action create hello index.js
ok: created action hello
We can now invoke this action
$ wsk action invoke hello -r
{
"msg": "hello world"
}
# with params
$ wsk action invoke hello -r -p name upkar
{
"msg": "hello upkar"
}
If you were paying close attention you would have noticed that when you run the jar file, it opens a browser with the new OpenWhisk Function Playground! This makes it even easier to write and test your functions if you are new to OpenWhisk. Go ahead and try it out!
How cool was that! If you like this, please give the repo some love! More to come on how this blazingly fast jar can help developers in their Serverless journeys.
Top comments (1)
I followed your steps above but I got the error below: