2

Google Cloud Functions Tutorial : Debugging Local Functions

 3 years ago
source link: https://rominirani.com/google-cloud-functions-tutorial-debugging-local-functions-357c24829198
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Google Cloud Functions Tutorial : Debugging Local Functions

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 thefunctions startcommand) 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:

Image for post
Image for post

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

Go to the Sources tab and put your breakpoint:

Image for post
Image for post

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:

Image for post
Image for post

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK