Cloud Native 11 min read

HarmonyOS ArkTS & Huawei Cloud FunctionGraph: Edge-Cloud Collaboration Implementation

This article explains how to implement edge-cloud collaboration using HarmonyOS ArkTS for lightweight client-side development and Huawei Cloud FunctionGraph serverless functions for professional cloud-side processing, covering core concepts, advantages, functions, scenarios, a comparison with traditional ECS/containers, quick-start steps, and complete code examples for both ArkTS HTTP requests and FunctionGraph functions.

51CTO HarmonyOS Developer Community
51CTO HarmonyOS Developer Community
51CTO HarmonyOS Developer Community
HarmonyOS ArkTS & Huawei Cloud FunctionGraph: Edge-Cloud Collaboration Implementation

Introduction to Huawei Cloud FunctionGraph

Huawei Cloud FunctionGraph is a Serverless Function-as-a-Service (FaaS) offering. Its core value lies in zero operations, automatic elasticity, and pay-per-invocation billing, allowing developers to focus solely on business logic without managing servers.

Core Positioning

Event-driven function hosting compute service on Huawei Cloud.

Focus on function-granularity development; no need to manage underlying servers, networks, or storage.

Automatic elastic scaling, high reliability, and pay-as-you-go pricing.

Core Advantages

(1) Extreme Elasticity

Millisecond-level auto-scaling based on request concurrency, easily handling traffic spikes.

Smart instance pre-warming to mitigate cold-start latency.

Proprietary Snapshot technology reduces image cold-start from minutes to seconds.

(2) Simplified Development & Deployment

Supports Node.js, Python, Java, Go, C#, PHP, and custom runtimes.

Multiple code upload methods: online editing, ZIP/JAR packages, OBS import.

IDE plugins and local debugging tools enable hour-level development and minute-level deployment.

Built-in Initializer interface separates initialization from request logic for performance optimization.

(3) Ultimate Cost Efficiency

Billing by invocation count plus runtime duration at millisecond granularity.

Zero cost when functions are not running; idle resources incur no charge.

Resource utilization improved by 50%+, costs reduced up to 90%.

(4) High Reliability & Operability

Multi-AZ deployment with automatic failure recovery.

End-to-end monitoring, log querying, and alerting integration.

Smooth upgrades with zero business interruption.

(5) Rich Triggers & Ecosystem

Supports 10+ trigger types including APIG (HTTP), Timer, OBS, SMN, DMS, CTS.

Seamless integration with Huawei Cloud storage, database, messaging, and AI services.

Visual Function Workflow orchestration, compatible with CNCF WorkFlow standard.

Core Functions

Function Management: Create/update/delete, version management, canary releases.

Event Triggering: HTTP requests, timers, file uploads, messages, logs, cloud service operations.

Elastic Scaling: Automatic instance scheduling by concurrency with load balancing.

Monitoring & Logs: Invocation count, latency, error rate, resource usage, real-time logs.

Function Workflow: Visual orchestration of multiple functions to build complex workflows.

Security & Permissions: IAM permissions, VPC internal access, key management.

Typical Application Scenarios

Web/API Services: Rapidly build serverless APIs, mini-program/app backends.

Data Processing: OBS file upload auto-triggers image/video transcoding, ETL, data cleansing.

Scheduled Tasks: Periodic reports, data synchronization, log cleanup, batch computing.

Message Processing: Real-time Kafka/RabbitMQ consumption, alert/notification handling.

AIGC/AI Inference: Model inference, content generation, image recognition with elastic compute.

IoT/Edge: Device data reporting, rule engines, edge computing linkage.

Comparison with Traditional ECS/Containers

Resource Management: FunctionGraph is fully managed (zero ops); ECS/containers require manual config, deployment, scaling, monitoring.

Elasticity: FunctionGraph offers millisecond-level auto-scaling; ECS/containers rely on manual/semi-auto scaling with high latency.

Billing: FunctionGraph charges per invocation + duration (zero cost when idle); ECS/containers charge per instance/container time (idle still billed).

Development Efficiency: FunctionGraph focuses on business logic with minute-level deployment; ECS/containers require infrastructure attention with longer cycles.

Cost: FunctionGraph provides pay-as-you-go with high utilization; ECS/containers involve fixed resources prone to waste.

Quick Start Guide

Log in to Huawei Cloud console → enter FunctionGraph.

Create a function: choose runtime, upload code or edit online.

Configure triggers (e.g., APIG, Timer, OBS).

Deploy, test, and monitor invocations.

FunctionGraph Code Example (Node.js)

exports.handler = async (event, context) => {
// Define an array
let arrs = ["Jinling Institute of Technology", "Nanjing Institute of Technology", "Nanjing Xiaozhuang University"];
// Define a constant
const output = {
'statusCode': 200,
'headers': {
'Content-Type': 'application/json'
},
'isBase64Encoded': false,
'body': JSON.stringify(arrs),
};
return output;
};

HarmonyOS ArkTS HTTP Module (@ohos.net.http)

The ArkTS HTTP module (based on @ohos.net.http) is the core network request API provided by HarmonyOS for the application layer. It supports HTTP/HTTPS protocols with GET/POST/PUT/DELETE methods, and includes built-in timeout control, request header configuration, cookie management, and certificate verification, adapting to HarmonyOS multi-device forms (phones, tablets, wearables, vehicle systems).

Core Features of ArkTS HTTP Module

(1) Full Protocol Support

Supports HTTP 1.1/2.0 and HTTPS (TLS 1.2/1.3).

Supports GET, POST, PUT, DELETE, HEAD, OPTIONS methods.

Supports form submission (form-data/x-www-form-urlencoded), JSON request bodies, file upload/download.

(2) Security & Compliance

Enforces HTTPS certificate verification (configurable custom certificates).

Supports automatic cookie management and manual configuration.

Adapts to HarmonyOS network permission control (requires ohos.permission.INTERNET permission).

(3) Usability Design

Asynchronous non-blocking calls (Promise/Callback) aligning with ArkTS async paradigm.

Supports request timeout settings and retry mechanisms.

Built-in response code and header parsing; no manual stream handling needed.

(4) Multi-Device Adaptation

Unified API across HarmonyOS device forms (lite/standard/enhanced systems).

Supports network state awareness; can combine with @ohos.net.connection for offline handling.

Basic Usage Steps (ArkTS + Stage Model)

Prerequisite: Declare Network Permission

In module.json5, declare the required network permission:

{ "module": { "requestPermissions": [ { "name": "ohos.permission.INTERNET" } ] } }

ArkTS Code to Call Huawei Cloud Function

import { http } from "@kit.NetworkKit";
@Entry
@Component
struct CloudPage {
build() {
Column() {
Button("Click to Request Huawei Cloud Function").onClick(() => {
let httpRequest = http.createHttp();
httpRequest.request("https://ed0a81022a6345cf9b6284cb7e5418ab.apic.cn-north-4.huaweicloudapis.com/userstr", (error, datas) => {
if (!error) {
let resultDatas = datas.result;
console.log("Received data from Huawei Cloud: " + resultDatas);
} else {
console.log("Network access error: " + JSON.stringify(error));
}
});
})
.width("100%").height("100%").backgroundColor("#ccffcc")
.justifyContent(FlexAlign.Center);
}
}
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

51CTO HarmonyOS Developer Community
Written by

51CTO HarmonyOS Developer Community

The HarmonyOS Developer Community is a learning-oriented community for developers to learn, communicate, ask questions, and share.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.