January 8, 2017 | Written by: Andrew Trice
Categorized: Compute Services | How-tos
Share this post:
It’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: 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.
Check out this overview.
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
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.
First things first, launch the debugger using the
wskdb command. This launches the debugger, where you can invoke commands to debug your actions:
The available commands are:
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):
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.
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.