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
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
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
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 (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
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
Cloud Transformation
Well-Architected Framework
Cloud Adoption 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
KooMessage
KooPhone
KooDrive

FunctionGraph and IaC

Updated on 2025-03-14 GMT+08:00

Combination of FunctionGraph and IaC

Most FunctionGraph functions do not run independently, but work with storage, gateways, databases, and message queues to form serviceless applications. Infrastructure as code (IaC) automates the frequent deployments and updates of functions and triggers. This approach shortens the development cycle, simplifies configuration management, and maintains the consistency of resource deployment.

Suitable IaC Tools for FunctionGraph

Resource Formation Service (RFS) is a new final-state cloud resource orchestration engine that fully supports Terraform (HCL and Provider), the industry's de facto standard for infrastructure as code. It automatically builds cloud resources in batches based on open ecosystem templates that use the HashiCorp Configuration Language (HCL) syntax. With RFS, you can create, manage, and upgrade cloud resources (such as FunctionGraph functions, APIG gateways, and database instances) efficiently, securely, and consistently.

Getting Started with RFS for FunctionGraph

  1. Create the Python script file index.py with the following content:

    # -*- coding:utf-8 -*-
    import json
    def handler (event, context):
        return {
            "statusCode": 200,
            "isBase64Encoded": False,
            "body": json.dumps(event),
            "headers": {
                "Content-Type": "application/json"
            }
        }

  2. Compress index.py into index.zip, upload the ZIP file to an OBS bucket, and obtain the file's object link in the bucket.
  3. Create the variables.tf file using the following content to define the parameters to be used in your RFS template.

    variable "enterprise_project_id" {
      type        = string
      description = " Specifies enterprise_project_id"
      default     = "0"
    }
    variable "agency_name" {
      type        = string
      description = " Specifies the agency to which the function belongs."
      default     = ""
    }
    variable "region" {
      type        = string
      description = " Specifies the region."
      default     = "cn-north-7"
    }
    variable "code_url" {
      type        = string
      description = "code_url"
    }
    variable "apig_id" {
      type        = string
      description = "apig_id"
      default     = ""
    }

  4. Create the RFS template file main.tf using the following content to define functions and triggers.

    variable "enterprise_project_id" {
      type        = string
      description = " Specifies enterprise_project_id"
      default     = "0"
    }
    variable "agency_name" {
      type        = string
      description = " Specifies the agency to which the function belongs."
      default     = ""
    }
    variable "region" {
      type        = string
      description = " Specifies the region."
      default     = "cn-north-7"
    }
    variable "code_url" {
      type        = string
      description = "code_url"
    }
    variable "apig_id" {
      type        = string
      description = "apig_id"
      default     = ""
    }

  5. Compress main.tf and variables.tf into the components.zip file.
  6. Log in to the RFS console, and choose Stacks > Create Stack as shown in Figure 1. For details, see Creating a Stack.

    Figure 1 RFS console

  7. Set parameters as shown in Figure 2, and upload components.zip. Then click Next.

    Figure 2 Setting parameters

  8. On the Configure Parameters page, set the following parameters, and click Next.

    • enterprise_project_id: enterprise project ID
    • agency_name: function agency name
    • region: region ID. Obtain it from Regions and Endpoints.
    • code_url: OBS object link obtained in step 2
    • apig_id: APIG gateway ID

  9. On the Configure Stack page, specify an IAM agency, retain the default values for other parameters, and click Next to confirm the deployment of this stack. The specified function and resource are automatically created on the FunctionGraph console.
  10. Log in to the FunctionGraph console, and click the function name in the function list to go to the details page. Choose Configuration > Triggers, locate the APIG trigger, copy its calling URL, and paste the URL into your browser or run the following curl command.

    curl -s <Trigger_Invoke_URL>  # Replace <Trigger_Invoke_URL> with the calling URL of your APIG trigger.

    The response is a JSON representation of the selected attributes in the original event object. It contains information about the request sent to the APIG endpoint. The following is an example response:

    HTTP/1.1 200 OK
    Content-Length: 658
    Connection: keep-alive
    Content-Type: application/json
    Date: Wed, 12 Mar 2025 08:59:18 GMT
    Server: api-gateway
    Strict-Transport-Security: max-age=31536000; includeSubdomains;
    X-Apig-Latency: 52
    X-Apig-Ratelimit-Api: remain:97,limit:100,time:1 minute
    X-Apig-Ratelimit-Api: remain:29973,limit:30000,time:1 second
    X-Apig-Ratelimit-Api-Allenv: remain:199,limit:200,time:1 second
    X-Apig-Ratelimit-Api-Allenv: remain:29973,limit:30000,time:1 second
    X-Apig-Ratelimit-User: remain:3995,limit:4000,time:1 second
    X-Apig-Upstream-Latency: 14
    X-Cff-Billing-Duration: 1
    X-Cff-Invoke-Summary: {"funcDigest":"e6e9c99b8f5b9d6f9408d5210263330","duration":0.756,"billingDuration":1,"memorySize":128,"memoryUsed":33.207,"podName":"pool22-300-128-fusion-844bdc7755-bh55w","gpuMemorySize":0,"ephemeralStorage":512}
    X-Cff-Request-Id: b43781ee-49f3-4762-8c24-236c718d3391
    X-Content-Type-Options: nosniff
    X-Download-Options: noopen
    X-Frame-Options: SAMEORIGIN
    X-Func-Err-Code: 0
    X-Is-Func-Err: false
    X-Request-Id: 90a48d7a4c699780579f4edc8983cdaf
    X-Xss-Protection: 1; mode=block;
     
    {"requestContext": {"requestId": "90a48d7a4c699780579f4edc8983cdaf", "apiId": "01127600bb9f4d2ca8e532d1c378d8c8", "stage": ":DEBUG"}, "queryStringParameters": {}, "path": "/nxy-sasa", "httpMethod": "GET", "isBase64Encoded": true, "headers": {"host": "47f32d1efa1742f5a7ee5b720ca9c4a5.apig.cn-east-3.huaweicloudapis.com", "content-type": "application/json", "x-forwarded-host": "47f32d1efa1742f5a7ee5b720ca9c4a5.apig.cn-east-3.huaweicloudapis.com", "user-agent": "APIGatewayDebugClient/1.0", "x-forwarded-port": "443", "x-forwarded-proto": "https", "x-request-id": "90a48d7a4c699780579f4edc8983cdaf", "x-apig-mode": "debug"}, "body": "", "pathParameters": {}}

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

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback