Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Cloud Data Center
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
Domain Name Service
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
DataArts Studio
Data Warehouse Service
Cloud Search Service
DataArts Lake Formation
DataArts Fabric
Data Ingestion Service
Data Lake Visualization
Data Lake Factory
IoT
IoT Device Access
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
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Industry Video Management Service
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
Huawei Cloud Astro Canvas
Huawei Cloud Astro Zero
CodeArts Governance
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Business 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 (CCI)
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
Meeting
AI
ModelArts
PanguLargeModels
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Cloud Transformation
Cloud Adoption Framework
Well-Architected Framework
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
Blockchain
Blockchain Service
Web3 Node Engine Service
MacroVerse aPaaS
CloudDevice
KooDrive
Help Center/ FunctionGraph/ Getting Started/ Creating a Function from Scratch and Executing the Function

Creating a Function from Scratch and Executing the Function

Updated on 2025-09-11 GMT+08:00

This section describes how to quickly create and test a HelloWorld function on the FunctionGraph console.

Prerequisites

  1. View free quota.

    FunctionGraph offers a free tier every month, which you can share with your IAM users. For details, see Free Tier

    If you continue to use FunctionGraph after the free quota is used up, your account goes into arrears if the balance is less than the bill to be settled. To continue using your resources, top up your account in time. For details, see Topping Up an Account.

  2. Grant the FunctionGraph operation permissions to the user.

    To perform the operations described in this section, ensure that you have the FunctionGraph Administrator permissions, that is, the full permissions for FunctionGraph. For more information, see Permissions Management.

Step 1: Create a Function

  1. Log in to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
  2. Click Create Function in the upper right corner and choose Create from scratch.
  3. Configure basic function information by referring to Figure 1. Then, click Create Function.
    Table 1 Parameters required for creating a function

    Parameter

    Description

    Example Value

    Function Type

    Select Event Function.

    An event function is triggered by a specific event, which is usually a request event in JSON format.

    Event Function

    Region

    Select the region where the function is located.

    Regions are geographic areas isolated from each other. Resources are region-specific and cannot be used across regions through internal network connections. Select a region near you to ensure the lowest latency possible.

    CN East-Shanghai1

    Function Name

    Enter a function name. The naming rules are as follows:

    • Consists of 1 to 60 characters, and can contain letters, digits, hyphens (-), and underscores (_).
    • Start with a letter and end with a letter or digit.

    HelloWorld

    Enterprise Project

    Select the enterprise project to which the function belongs. Enterprise projects let you manage cloud resources and users by project.

    The default value is default. You can select the created enterprise project.

    If the Enterprise Management service is not enabled, this parameter is unavailable. For details, see Enabling the Enterprise Project Function.

    default

    Agency

    Select an agency for the function. An agency is used to authorize FunctionGraph to access other cloud services. If FunctionGraph does not access any cloud service, you do not need to select an agency.

    By default, Use no agency is used. You can select an existing agency.

    If no default agency is available, FunctionGraph allows you to quickly create a default agency named fgs_default_agency..

    Use no agency

    Permission Policies

    This parameter is displayed only when an agency is selected.

    For details about how to adjust the permission policies on the IAM console, see Modifying an Agency.

    -

    Runtime

    Select a runtime to compile the function.

    For details about the runtimes supported see Supported Runtimes.

    • CloudIDE supports only online editing of Node.js, Python, PHP, and custom runtimes.
    • After a function is created, the runtime language cannot be changed.

    Node.js 16.17

    Advanced Settings

    • Public Access: If this feature is enabled, functions can access services on the public network through the default NIC. The public network access bandwidth is shared among users and applies only to test scenarios.
    • VPC Access: If this feature is enabled, functions will use the NIC bound to the configured VPC for network access, and the default NIC of FunctionGraph will be disabled. That is, the Public Access parameter does not take effect.

      To enable this feature, you need to configure an agency with VPC management permissions. If you select Use no agency in the Basic Information area, this feature cannot be enabled.

    • Collect Logs: After it is enabled, logs generated during function execution will be reported to LTS.

      LTS will be billed on a pay-per-use basis. For details, see LTS Pricing Details.

    • Static Encryption with KMS (supported only in the LA-Sao Paulo1 region): Select whether to use KMS static code encryption.

      DEW is billed by the pay-per-use mode. For details, see DEW Billing.

    • Public Access: Enabled.
    • VPC Access: Disabled.
    • Collect Logs: Disabled.
    • Static Encryption with KMS: Disabled.
    Figure 1 Creating a function

  1. Configure the code source, copy the following code to the code window, and click Deploy.
    The sample code enables you to obtain test events and print test event information.
    exports.handler = function (event, context, callback) {
        const error = null;
        const output = `Hello message: ${JSON.stringify(event)}`;
        callback(error, output);
    }

Step 2: Test the Function

  1. On the function details page, click Test. In the displayed dialog box, create a test event.
  2. Select blank-template, set Event Name to test, modify the test event as follows, and click Create.
    {
        "hello": "function"
    }
    Figure 2 Configuring a test event

Step 3: View the Execution Result

Click Test and view the execution result on the right.

  • Function Output: displays the return result of the function.
  • Log Output: displays the execution logs of the function.
  • Summary: displays key information of the logs.
    Figure 3 Viewing the execution result
NOTE:

A maximum of 2 KB logs can be displayed. For more log information, see Querying Function Logs.

Related Information

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback
咨询盘古Doer

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback