Google Cloud Functions Tutorial : Debugging Local Functions

Romin Irani
Romin Irani’s Blog
2 min readApr 24, 2018

This is part of a Google Cloud Functions Tutorial Series. Check out the series for all the articles.

In the previous post, we saw how we can use the Local Emulator to deploy and test our functions locally. Can we debug the functions too?

Let’s try that out as per the instructions below:

In the Github cloned directory, go to the folder hello-localfunctions. The index.js file is shown below:

exports.localfunction = (req, res) => {
console.log(‘Hello Google Cloud Functions Emulator’);
res.send(‘Success’);
};

This is a straightforward HTTP trigger based function. Assuming that you have the Local Emulator running (via the functions start command) deploy the function as per the command given below:

$ functions deploy localfunction --trigger-http

Once the function is deployed successfully, you can check if it is present in the list of Local functions as given below:

$ functions list

┌────────┬───────────────┬─────────┬────────────────────────────────│ Status │ Name │ Trigger │ Resource │
├────────┼───────────────┼─────────┼────────────────────────────────│ READY │ localfunction │ HTTP │ http://localhost:8010/mindstormclouddemo/us-central1/localfunction

You can now use the inspect command as shown below:

$ functions inspect localfunction

Debugger for localfunction listening on port 9229.

Notice the last line. It says that a Debugger is started on port 9229.

Launch Google Chrome browser and type in chrome://inspectin the URL. It should give you a screen as shown below:

Notice the Remote target. Click on the inspect link in the browser window above.

Go to the Sources tab and put your breakpoint:

Now, you can invoke the function from the terminal as given below:

$ functions call localfunction

This will result in the code execution stopping at the breakpoint that we have placed as shown below:

Simply run the rest of the code. You will find that the terminal window via which you invoked the function will exit too with the “Success” message.

Proceed to the next part : Cloud Functions Pricing or go back to the Google Cloud Functions Tutorial Home Page.

--

--

Romin Irani
Romin Irani’s Blog

My passion is to help developers succeed. ¯\_(ツ)_/¯