Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Local Debugging with VSCode

Updated on 2024-03-05 GMT+08:00

Introduction

Huawei Cloud FunctionGraph is a Visual Studio Code (VSCode) plug-in of Huawei Cloud serverless products. With this plug-in, you can:

  • Quickly create local functions.
  • 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

  1. Open VSCode, search for Huawei Cloud FunctionGraph in the app store, and install it.
    Figure 1 Searching for and installing Huawei Cloud FunctionGraph
  2. 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

  1. Click the Huawei Cloud FunctionGraph plug-in icon, click the login link, and select a login mode. If you select login with AK/SK, obtain an AK/SK. For details, see Creating an Access Key.
  1. Select a region to view function information.

  2. 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

  1. 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.

  1. After the local function is created, the handler file is automatically opened.
  2. You can customize the function's configuration by modifying the automatically generated configuration file. The parameters are as follows:
    HcCrmTemplateVersion: v2
    Resources:
        Type: HC::Serverless::Function
        Properties:
            Name: functionName //Function name
            Handler: handler // Handler of the function
            Runtime: runtime // Function runtime
            CodeType: inline // Default
            CodeFileName: index.zip // Default
            CodeUrl: ""
            Description: '' // Function runtime
            MemorySize: 128 // Memory for executing the function
            Timeout: 30 // Function timeout, in seconds.
            Version: latest // Default
            Environment:
                Variables: {} // Environment variables
            InitializerHandler: "" // Function initializer
            InitializerTimeout: 0 // Initialization timeout of the function
            EnterpriseProjectId: "0" // Enterprise project
            FuncType: v2
            URN: "" // Function URN, which is generated after the function is downloaded.

Deploying a 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.

  • If the deployment is successful, a success message is displayed in the lower right corner of the page. Switch to the target region to view the deployment result.
  • If the deployment fails, view the error log in the Output area and rectify the fault.

Local Debugging

  1. Node.js
    • Prerequisites

      Node.js has been installed in the local environment.

    • Default mode
      Click Local Debug of the handler method, configure the event content, and click Invoke for debugging.
      Figure 3 Clicking Local Debug
      Figure 4 Configuring the event content
    • Debugging with VS Code

      Create the main.js file in the function folder and copy the following content to this file. Click the 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 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

      Java has been installed. VS Code supports Java testing.

    In the test directory of the function folder, open the TriggerTestsTest.java file, and click the icon on the left. Then, click Add Config, select Java, and press F5 to start debugging.

Other Functions

  • Opening in Portal

    Right-click the target function, and choose Open in Portal. The function details page is displayed.

  • Executing a Cloud Function
    1. Right-click the target function and choose Invoke Function... from the shortcut menu.
    2. In the Invoke Function panel, select the event to be passed 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 Upload Function... from the shortcut menu, and select a ZIP package to upload.

  • Deleting a Cloud Function
    1. Right-click the function to be deleted and choose Delete... from the shortcut menu.
    2. 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.

Usamos cookies para aprimorar nosso site e sua experiência. Ao continuar a navegar em nosso site, você aceita nossa política de cookies. Saiba mais

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback