Debugging Apache OpenWhisk Functions with VS Code

As a developer I develop and debug code locally as much as possible. I’ve written some sample code that shows how to debug Node.js OpenWhisk functions via Visual Studio Code.

The sample code explains how to debug single-file functions, zipped multi-file functions as well as Node.js functions in Docker containers.

The following screenshot shows how functions that run in Docker can be debugged from Visual Studio Code. In order to do this, a volume is used to share the files between the IDE and the container and VS Code attaches a remote debugger to the Docker container. The functions can be changed in the IDE without having to restart the container. nodemon restarts the Node application in the container automatically when files change.

debugging-docker-3

Get the code from GitHub.

Watch the video to see how to debug OpenWhisk functions with Visual Studio Code.

If you want to try out OpenWhisk in the cloud, you can get a free account on the IBM Cloud.

  • http://www.raymondcamdencom/ Raymond Camden

    I’m really confused by how this all works. Maybe this comments belongs on the Git repo instead, but I figured I’d start here.

    So – I did read this. https://github.com/nheidloff/openwhisk-debug-nodejs

    It tells you to clone a repo. Ok, first off, what is the repo for? I mean, assuming I’ve got my own folders of OpenWhisk code and stuff, how does this repo work with my own code? Is it just samples? The docs seem to say as much, but I can’t tell. Does it maybe install a global executable to help me debug? All it says is to run npm install and then open Code to it, but again, how does that relate to my own code?

    Also – where is Docker used?

    I see now that there is a launch configuration in the repo… ok… so I’d need to copy that to my own projects, right?

    I stopped reading at the end of the section on single file functions and I do not see anything about Docker. Does the launch configuration just make that work?

    • http://www.raymondcamdencom/ Raymond Camden

      Ok… so it did “just” work. So a few things:

      a) Maybe make it clearer (or simpler for me 😉 how to use this with *existing* code.
      b) Is the Docker stuff just for people doing Docker stuff w/ OpenWhisk? If I’m not, can I skip that? And if so, maybe the instructions should make it clear you don’t need it?

      • Niklas Heidloff

        Raymond, yes, the repo contains just samples. You can use the same pattern to debug your own functions without having to clone or install anything.

        Yes, the Docker section is only for people who want to write functions in their own images/containers. The same debug mechanism in VS Code should work for functions developed in other languages in containers, e.g. Java, Go, etc. but I haven’t tried it yet.

        I will add these comments to the repo to make it clearer that this is a sample/pattern and not a tool/extension.

        BTW: In the simplest case just clone the repo and copy/overwrite your function code in function.js and run the debug configuration ‘function.js’.

        • http://www.raymondcamdencom/ Raymond Camden

          I think that I’d like to see is instructions showing how to do this with existing code. I think in most cases, people would want that. Maybe a blog post (or 3, one for single, one for zip, one for Docker), showing taking an existing project/folder, and adding this support in. Would that make sense? (Btw, I’ll gladly write this up myself for the first two if you want help. :)

          • Niklas Heidloff

            I’ve added some notes to the repo.

            Would be great if you could blog this. I can help but have little time this and next week.

          • http://www.raymondcamdencom/ Raymond Camden

            I always feels a bit wonky when I “leech” on content like this – but as you said it was ok, I will. :) It’s on my queue now. Thank you, btw!