Debugging Cloud Functions Locally

Doğan Burak Ziyanak
Huawei Developers
Published in
3 min readApr 8, 2022

Hello everyone,

In this tutorial, I will demonstrate how to debug a function using the cloud debugging plugin which can work on Visiual Studio Code.

Introduction

Cloud Functions enables serverless computing. It provides Function as a Service (FaaS) capabilities, which help simplify app development and O&M by splitting service logic into functions, and offers the Cloud Functions SDK that works with Cloud DB and Cloud Storage so that your app functions can be implemented more easily. The service automatically scales in or out functions based on actual traffic, freeing you from server resource management and helping you reduce costs.

Previously, Cloud Functions allows you to debug functions only after they are uploaded to the cloud, and it is impossible for you to debug functions at breakpoints. To address your problem, Cloud Functions of the latest version supports a debugging plugin. It is particularly useful for situations where you want to debug your function before deployment.

Configuring the Environment

To use the plugin, you need to install Visual Studio Code and Docker Desktop.

a) Download and Install Visual Studio Code.

b) Download and install Docker Desktop, and enable Hyper-V. Right-click the taskbar, and go to Apps and Features > Programs and Features. On the displayed page, click Turn Windows features on or off in the upper left corner, and select Hyper-V. Then restart your computer.

Installing the Cloud Functions Plugin in Visual Studio Code

a) Obtain the AppGallery Connect toolkit package from HUAWEI Developers and decompress it.

b) Run the load_sandbox.bat script to load the sandbox.

c) Select Install from VSIX from EXTENSIONS, and click appgallery-connect-toolkit-1.0.15.vsix.

d) After installation, the AppGallery Connect icon is displayed. Go to File > Preferences > Settings, and click Edit in settings.json to create a settings.json file. Add appgallery.connect.toolkit.container”: “agc-cloudfunction-runtime:1.0.15 to the file. Ensure that, the added content consists of only single-byte characters.

Debugging a Function Locally

a) Create a local function.

b) Click the plus sign to configure the function, including its name and type.

c) Select a trigger event. The event type may vary depending on the trigger type. If the trigger type is changed, change the event type accordingly.

Calling the Function

a) Right-click the function and choose the option for starting the local sandbox. Then the following command will be automatically executed.

b) After that, right-click the function and choose the option for calling the function.

The function calling result will be displayed in the command output.

Conclusion

We have briefly explained all steps for how to debug a function locally in Visual Studio Code.

Give this a try if you’re interested.

Hope you enjoy with the content and let’s meet soon with new articles! Please do not hesitate to contact from developer forum in case if you have any questions:

https://forums.developer.huawei.com/forumPortal/en/

--

--