Strategy丨CloudBase Toolkit cloud function debugging

Strategy丨CloudBase Toolkit cloud function debugging

Tencent CloudBase Toolkit plugin version 0.2.0 supports two debugging modes: local debugging of cloud functions and cloud debugging.

  • Local debugging : Using CloudBase CLI run in local analog functions Node.js cloud, cloud function eventand contextare simulation parameters for local development
  • Cloud debugging : Use cloud function instances in the cloud for debugging. All parameters and environments are consistent with the cloud, which is suitable for locating complex online problems.

Local debugging

The CloudBase CLI tool is required for local debugging. Please install the CloudBase CLI tool first.

Installation address:

https://docs.cloudbase.net/cli/intro.html

Steps

1. Make sure there is a current project root directory of the cloudbaserc.jsonconfiguration file, and if not, select [generate] the right cloudbaserc profile resource management area;

2. Put a breakpoint at the position that needs to be debugged;

3. Select the cloud function directory to be debugged, right-click [Debug Cloud Function], and select [Local Debugging] in the pop-up options.

Cloud debugging

Cloud debugging will run a cloud function instance for local connection debugging. Cloud debugging requires the use of cloud function instances, which will incur corresponding operating costs.

Cloud debugging can only be triggered through the [Debug Cloud Function] of the CloudBase Toolkit, and cannot be triggered through the Debug panel.

note:

  • Before starting the operation, it is recommended that you read the precautions below.
  • It is not recommended to perform cloud debugging on the production environment or frequently called cloud functions. It may fail to hit the debugging and block other requests.

Steps

1. Make sure there is a current project root directory of the cloudbaserc.jsonconfiguration file, and if not, select [generate] the right cloudbaserc profile resource management area;

2. Select the cloud function directory that needs to be debugged, right-click [Debug Cloud Function], and select [Cloud Debugging] in the pop-up options;

3. Put a breakpoint at the position that needs to be debugged;

4. Trigger your cloud function. You can trigger your cloud functions from the applet, SDK or Tencent Cloud console according to your usage.

Precautions

The current cloud debugging capabilities of cloud functions are in the Beta stage, and you are welcome to try it out and give us feedback on problems or suggestions in use.

When using the cloud debugging function of cloud functions, you need to understand the following information and points of attention:

1. Cloud debugging uses an actual running concurrent instance of cloud function for debugging.

2. Due to the randomness of the trigger event, if there are multiple instances, the trigger event may randomly fall on an instance, so not any request can hit the debugging concurrent instance and start debugging.

3. Debugging breakpoints when running paused: If it is not running for a long time and does not return, it may cause the trigger to report an error, such as an API gateway prompting timeout. The instance is still in the timing state, and will continue to execute until the function is completed when the debugging is completed. The total time spent in the whole process is recorded as the running time of this function.

4. From the triggering of concurrent instance operation to the final completion of debugging, the maximum time for a single execution to complete is 900 seconds. That is, if the execution is interrupted for 900 seconds during debugging, the execution will be forcibly terminated, and the statistics and measurement will be performed according to the function running time of 900 seconds and timeout.

5. With the debugging capability of the current version, the cloud function timeout will be configured to 900 seconds, and the timeout will be reset to the normal value when the debugging is exited normally. If the debugging command exits abnormally or is forcibly terminated, the cloud function timeout will not be set to a normal value. At this time, you can modify the cloud function timeout configuration by deploying it again (command line) or manually editing (console).

Configuration item

In general, you don't need to care about the configuration options for debugging. CloudBase Toolkit will automatically generate the relevant debugging configuration and start the debugging function.

Local debugging

The following are local debugging launchconfiguration includes the following options:

  • type: VS Code debugging type, fixed value is node
  • request: VS Code debug startup type, fixed value attach
  • port: debugging process port, the default is 9229
  • name: name of the current debug item, the default is "[函数名] 云函数本地调试"in the form of
  • entry: the name of the target function to be debugged
  • cloudbaseLocal: Mark the current debugging item as applicable to CloudBase Toolkit local debugging
{"configurations": [{"type": "node", "request": "attach", "port": 9229, "name": "[app] Cloud function local debugging", "entry": "app" , "cloudbaseLocal": true} ]}

The following is a cloud debug launchconfiguration includes the following options:

  • type: VS Code debugging type, fixed value is node
  • request: VS Code debug startup type, fixed value attach
  • port: debugging process port, the default is 9222
  • name: name of the current debug item, the default is "[函数名] 云函数云端调试"in the form of
  • remoteRoot: The root path of the cloud code, fixed as /var/user
  • localRoot: the root path of the local code
  • cloudbaseRemote: Mark the current debugging item as CloudBase Toolkit cloud debugging configuration item
{"type": "node", "request": "attach", "name": "[app] Cloud function cloud debugging", "port": 9222, "cloudbaseRemote": true, "remoteRoot": "/var/user", "localRoot": "${workspaceFolder}/functions/app"}
Reference: https://cloud.tencent.com/developer/article/1658784 Guide丨CloudBase Toolkit Cloud Function Debugging-Cloud + Community-Tencent Cloud