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
Help Center/ FunctionGraph/ User Guide (ME-Abu Dhabi Region)/ Building Functions/ Deploying a Function Using a Container Image

Deploying a Function Using a Container Image

Updated on 2023-11-21 GMT+08:00

Introduction

Package your container images complying with the Open Container Initiative (OCI) standard, and upload them to FunctionGraph. The images will be loaded and run by FunctionGraph. Unlike the code upload mode, you can use a custom code package, which is flexible and reduces migration costs. You can create event and HTTP functions by using a custom image.

For details about how to develop and deploy an HTTP function using a container image, see Developing an HTTP Function.

For details about how to develop and deploy an event function using a container image, see Developing an Event Function.

The following features are supported:
  • Downloading images

    Images are stored in SoftWare Repository for Container (SWR) and can only be downloaded by users with the SWR Admin permission. FunctionGraph will call the SWR API to generate and set temporary login commands before creating instances.

  • Setting environment variables

    Encryption settings and environment variables are supported. For details, see Configuring Environment Variables.

  • Attaching external data disks

    External data disks can be attached. For details, see Configuring Disk Mounting.

  • Reserved instances

    For details, see the description about reserved instances.

NOTE:

User containers will be started using UID 1003 and GID 1003, which are the same as other types of functions.

Prerequisites

You have created an agency with the SWR Admin permission by referring to Configuring Agency Permissions. Images are stored in SWR, and only users with this permission can invoke and pull images.

Procedure

  1. Log in to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
  2. On the Function List page, click Create Function in the upper right corner.
  3. Select Container Image. For details, see Table 1.
    Figure 1 Creating a function using a container image
    Table 1 Parameter description

    Parameter

    Description

    *Function Type

    Select a function type.

    Event function: triggered by triggers.

    HTTP function: triggered once HTTP requests are sent to specific URLs.
    NOTE:
    • The custom container image must contain an HTTP server with listening port 8000.
    • HTTP functions support APIG and APIC triggers only.
    • When creating an event function, create an HTTP server to implement a handler (method: POST, path: /invoke) and an initializer (method: POST, path: /init).
    • When calling a function using APIG, isBase64Encoded is valued true by default, indicating that the request body transferred to FunctionGraph is encoded using Base64 and must be decoded for processing.
    • The function must return characters strings by using the following structure.
      {
          "isBase64Encoded": true|false,
          "statusCode": httpStatusCode,
          "headers": {"headerName":"headerValue",...},
          "body": "..."
      }

    *Region

    Select a region where you will deploy your code.

    *Function Name

    Name of the function, which must meet the following requirements:

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

    *Enterprise Project

    Select a created enterprise project and add the function to it. By default, default is selected.

    Container Image

    Enter an image URL, that is, the location of the container image. You can click View Image to view private and shared images.

    Container Image Override

    • CMD: container startup command. Example: /bin/sh. If no command is specified, the entrypoint or CMD in the image configuration will be used. Enter one or more commands separated with commas (,).
    • Args: container startup parameter. Example: -args,value1. If no argument is specified, CMD in the image configuration will be used. Enter one or more arguments separated with commas (,).
    • Working Dir: working directory where a container runs. If no directory is specified, the directory in the image configuration will be used. The directory must start with a slash (/).
    • User ID: user ID for running the image. If no user ID is specified, the default value 1003 will be used.
    • Group ID: user group ID. If no user group ID is specified, the default value 1003 will be used.

    Agency

    Select an agency with the SWR Admin permission. To create an agency, see Creating an Agency.

    NOTE:
    • Command, Args, and Working dir can contain up to 5120 characters.
    • When a function is executed at the first time, the image is pulled from SWR, and the container is started during cold start of the function, which takes a certain period of time. If there is no image on a node during subsequent cold starts, an image will be pulled from SWR.
    • Public and private images are supported. For details, see Setting Image Attributes.
    • The port of a custom container image must be 8000.
    • The image package cannot exceed 10 GB. For a larger package, reduce the capacity. For example, mount the data of a question library to a container where the data was previously loaded through an external file system.
    • FunctionGraph uses LTS to collect all logs that the container outputs to the console. These logs can be redirected to and printed on the console through standard output or an open-source log framework. The logs should include the system time, component name, code line, and key data, to facilitate fault locating.
    • When an out of memory (OOM) error occurs, view the memory usage in the function execution result.
    • Functions must return a valid HTTP response.

Sample Code

The following uses Node.js Express as an example. During function initialization, FunctionGraph uses the POST method to access the /init path (optional). Each time when a function is called, FunctionGraph uses the POST method to access the /invoke path. The function obtains context from req.headers, obtains event from req.body, and returns an HTTP response struct.

const express = require('express');
const app = express();
const PORT = 8000;

app.post('/init', (req, res) => {
  res.send('Hello init\n');
});

app.post('/invoke', (req, res) => {
  res.send('Hello invoke\n');
});

app.listen(PORT, () => {
  console.log(`Listening on http://localhost:${PORT}`);
});

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