Compute Services

Using the new OpenWhisk Debugger

Share this post:

openwhisk_hero_smallIt’s no surprise that the popularity of serverless computing is rapidly gaining. Implicit scalability, event driven/automatic data processing, simplicity, reusability, composability, and reduced cost are just a few reasons that serverless programming models are taking off. One of the arguments that people sometimes give against using serverless programming models is that serverless actions can be harder to develop because you can’t attach a local debugger to them, but really, that’s no longer an issue now that we have wskdb.

wskdb: the OpenWhisk Debugger

If you haven’t seen it yet, now’s your opportunity to check out wskdb, the new/pre-beta OpenWhisk debugger. It allows you to debug OpenWhisk actions on your local machine, in a rich debugging environment, just like you are debugging local code.

In fact, you actually are debugging local code. When using the debugger, you attach to an action. Then, the invocation of that action gets re-routed to your dev machine, where you can debug and make local changes. When you are done debugging, you can push changes, or just disconnect. The re-routing gets cleaned up at that stage.

You can even debug specific actions within a sequence. Imagine that you have a sequence that is made up of actions A, B, C, and D. You can attach the debugger to any of these actions. So, if I want to debug action C, you attach to action C. When the sequence is invoked, actions A and B will be executed in the OpenWhisk environment, then action C will be invoked in your local debug environment, then action D will be executed back in the OpenWhisk environment.

You can use the OpenWhisk debugger to debug Node.js/JavaScript, Swift, or Python actions, and it gives you the ability to hit breakpoints, step through code, inspect memory values, and more.

Check out this overview.

Installation

Installing the OpenWhisk debugger should be a straightforward task. First, make sure that you have Node.js installed. I currently have Node.js v6.2 installed—I ran into a bug in the latest version of Node.js that prevented the debugger from working in v6.9, but this is known, and is being addressed.

Once you have Node.js installed, you can install the OpenWhisk debugger by running the following from a terminal:

npm install -g openwhisk-debugger

If you want to debug Swift actions, you’ll also need swiftc and lldb installed. If you’re on a Mac, you can get these by installing Xcode. If you want to debug Python actions, you’ll need the correct version of Python installed, which you can read about in more detail in the docs.

Usage

First things first, launch the debugger using the wskdb command. This launches the debugger, where you can invoke commands to debug your actions:

wskdb listing

The available commands are:

COMMAND            DESCRIPTION
list, l            List available actions
cli                Use the CLI debugger, when available
invoke, i          Invoke an action
inspect, ins, get  Inspect the details of an OpenWhisk action
fire, f            Fire a trigger
attach, a          Attach to an action
detach, d          Detatch from an action
diff               Show the pending diffs of a given action
publish, p         Publish pending changes to a given action
exit, quit, e, q   Quit the debugger
clean, c           Clean up debugging artifacts
create             Create an action
delete             Delete an action
help, h, ?         Print this help text

To debug an action, you must first run the attach command—this sets up the “plumbing” to be able to debug your action. Once the debugger has been attached, you use in invoke command (passing in arguments just like the OpenWhisk CLI). In the screenshot below, you can see how I am attaching and invoking into my Fibonacci action (which generates numbers in a Fibonacci sequence):

wskdb invoking an action

This will launch the debug process. For JavaScript/Node.js actions, this will be based on the familiar Chrome/Blink/Webkit/Node Inspector debugger as you can see in the image below.

debugging an OpenWhisk action

This provides the ability to inspect variables in memory, set breakpoints, step through code line-by-line, etc. … All of which are incredibly helpful development and debugging tools.

Debugging of Swift actions will use the LLDB debugger, and Python actions will use the Python debugger (pdb). If you’re not familiar with LLDB, See here for a quick reference of lldb commands. If you’re not familiar with pub, see here for quick reference of pub commands.

What next?

Sign up for Bluemix and start using OpenWhisk, and download the CLI for your serverless computing tasks today!

You can learn more about using the OpenWhisk debugger from the readme/docs, submit an issue if you find one, or you can make a contribution to the project directly. All community input is welcome.

Guess what else? It also works with the OpenWhisk extension for VS Code that I have discussed previously, but I’ll save the details on that for another blog post.

More stories
May 3, 2019

Kubernetes Tutorials: 5 Ways to Get You Building Fast

Ready to start working with Kubernetes? Want to build your Kubernetes skills? The five tutorials in this post will teach you everything you need to know about how to manage your containerized apps with Kubernetes.

Continue reading

May 3, 2019

Using Portworx to Deploy and Manage an HA MySQL Cluster on IBM Cloud Kubernetes Service

This tutorial is a walkthrough of the steps involved in deploying and managing a highly available MySQL cluster on IBM Cloud Kubernetes Service.

Continue reading

May 2, 2019

Kubernetes v1.14.1 Now Available in IBM Cloud Kubernetes Service

We are excited to announce the availability of Kubernetes v1.14.1 for your clusters that are running in IBM Cloud Kubernetes Service. IBM Cloud Kubernetes Service continues to be the first public managed Kubernetes service to support the latest upstream versions from the community.

Continue reading