Huawei Cloud FunctionGraph
简体中文
Huawei Cloud FunctionGraph is a Visual Studio Code (VSCode) plug-in of Huawei Cloud serverless product.
With this plug-in, you can:
- Quickly create functions locally
- Run and debug local functions and deploy them to the cloud.
- Pull the function list from the cloud, call cloud functions, and upload ZIP packages to the cloud.
Prerequisites
You have downloaded the VSCode tool (later than 1.63.0) and installed it.
Installing the Plug-in
Open VSCode, search for Huawei Cloud FunctionGraph in the app store, and install it.
Figure 1 Searching for and installing Huawei Cloud FunctionGraph
After the installation is successful, Huawei Cloud FunctionGraph is displayed in the plug-in list.
Figure 2 Installed plug-ins
Logging In to FunctionGraph Plug-in
Open the Huawei Cloud FunctionGraph plug-in on the left, log in with the AK/SK of your account, and enter information as prompted. For details about how to obtain AK/SK, see Creating an Access Key.
Select a region to view function information.
Show or hide desired regions, or log out of your account by referring to the following figure.
- Show region in the Explorer: Show the regions where you need to perform operations.
- Hide region from the Explorer: Hide the regions you do not need.
- Log Out: Log out of your account.
Creating a Function
On the plug-in panel, select Create Function or press Ctrl+Shift+p to search for the Create Function command. Then, specify the runtime, template, function name, and local folder as prompted. A function is created in the specified folder.
After the local function is created, the handler file is automatically opened.
Deploying the Function
Prerequisites
Ensure that the function code path is correct. The code of Node.js, Python, and PHP functions is stored in the src directory, and the code of other functions is stored in the root directory.
On the plug-in panel, select Deploy Function or press Ctrl+Shift+p to search for the Deploy Function command, and select a function and region as prompted.
- Deployment successful: A success message is displayed in the lower right corner of the page. Switch to the target region to view the deployment result.
- Deployment failed: View the error log in the Output area and rectify the fault.
Local Debugging
1. Node
Prerequisites
Node.js has been installed in the local environment.
1. Default mode
- Click Local Debug of the handler method, configure the event content, and click Invoke for debugging.
2. Debugging with VS Code
Create the main.js file in the function folder and copy the following content to this file. Click the run/debug icon on the left. Then, click Add Config, select Node.js, and press F5 to start debugging.
const handler = require('./index'); // Path of the function handler file. Modify it as required.
const event = { 'hello': 'world' }; // Test event. Modify it as required.
const context = {}; // Context class.
console.log(handler.handler(event, context));
2. Python
Prerequisites
Python has been installed in the local environment.
Create the main.py file in the function folder and copy the following content to this file. Click the run/debug icon on the left. Then, click Add Config, select Python, and press F5 to start debugging.
import sys
import index # Path of the function handler file. Modify it as required.
# The main method is used for debugging, and event is the selected debugging event.
if __name__ == '__main__':
....event = { 'hello': 'world' } # Test event. Modify it as required.
context = ''
content = index.handler(event, context)
....print('Returned value:')
print(content)
3. Java
Prerequisites
You have installed Java in your local environment. VSCode now supports Java testing.
In the test directory of the function folder, open the TriggerTestsTest.java file, and click the run/debug icon on the left. Then, click Add Config, select java, and press F5 to start debugging.
Other Features
Opening in Portal
Right-click a function and choose Open in Portal from the shortcut menu. The function details page is displayed.
Executing a Cloud Function
- Right-click the target function and choose Invoke Function from the shortcut menu.
- In the Invoke Function panel, select the event to be transferred and click Invoke. The function log and result are displayed in the Output area.
Downloading a Cloud Function
Prerequisites
You have been granted the permission (obs:object:GetObject) for obtaining bucket objects.
Right-click the function you want to download and choose Download from the shortcut menu. The function code is downloaded from the cloud to the specified local path, and the handler file is automatically opened.
Updating a Cloud Function
Right-click the target function, choose Update Function from the shortcut menu, and select a ZIP package to upload.
Deleting a Cloud Function
- Right-click the function to be deleted and choose Delete from the shortcut menu.
- In the confirmation dialog box, click Delete to delete the function.
Copying URN
Right-click the target function and choose Copy URN from the shortcut menu.