We recommend that you deploy function applications by using images if you need to use popular AI projects, such as Stable Diffusion WebUI, ComfyUI, retrieval-augmented generation (RAG), and TensorRT, that require GPU-accelerated instances for acceleration. This way, you can use container images as deliverables for functions to improve development and delivery efficiency.
Create a function
Log on to the Function Compute console. In the left-side navigation pane, click Functions.
In the top navigation bar, select a region. On the Functions page, click Create Function.
On the Create Function page, select GPU Functions. Configure the following parameters and click Create.
Basic Settings: Configure Function Name.
Code: Configure the runtime and code information of the function.
Parameter
Description
Example
Runtime
Use Sample Images: Select a sample image provided by Function Compute to quickly deploy image functions. Select an image from the image list below the Container Images parameter.
Use Container Registry Images: Click Select a Container Registry image below the Container Image parameter. In the Select Container Image panel that appears, specify the Container Image Instance and Container Registry Repository parameters, find the desired image in the image list, and then click Select in the Actions column on the right.
Use Sample Images
Container Image
Select an image.
Sample Images of SpringBoot Web Applications
Startup Command
Configure the startup command of the program. If no startup command is configured, the Entrypoint or CMD instruction in the image is used.
None
Listening Port
Specify the port on which the HTTP server in your code listens.
9000
Advanced Settings: Configure advanced settings of the function, such as the instance-related information and function execution timeout period.
Parameter
Description
Example
GPU Type
Specify the GPU card type. For more information about GPU card types, see Instance types and usage modes.
Tesla Series
Specifications
Specify specifications of the function, including GPU Memory Size, vCPU Capacity, and Memory Capacity based on your business requirements. For more information about billing, see Billing overview.
GPU Memory Size = 4 GB
vCPU Capacity = 2 vCPU
Memory Capacity = 4 GB
Size of Temporary Disk
Specify the size of the disk used to temporarily store files based on your business requirements. Default value: 512 MB.
Valid values:
512 MB: You are not charged for using a temporary disk of this size. Function Compute provides you with a free disk space of 512 MB.
10 GB: You are charged based on a disk size of 9.5 GB.
NoteData can be written to all directories in the temporary disk and shares the space of the temporary hard disk.
The lifecycle of the temporary disk is consistent with the lifecycle of the underlying instance. When the instance is recycled by the system, the data on the disk is also cleared. To persist files, you can use File Storage NAS (NAS) or Object Storage Service (OSS). For more information, see Configure a NAS file system and Configure an OSS file system.
512 MB
Execution Timeout Period
Specify the timeout period for a function execution. Unit: seconds. The default value is 60 and maximum value is 86400.
60
Instance Concurrency
Specify the instance concurrency. Function Compute supports the instance concurrency feature, which allows each instance to process multiple requests at a time.
20
Time Zone
Specify the time zone of the function. After you configure the time zone, the environment variable TZ with the specified time zone value is automatically added to the function.
UTC
Function Role
Specify the Resource Access Management (RAM) role of the function. Function Compute assumes this role to generate a temporary key for accessing your Alibaba Cloud resources and pass it to your code. For more information, see Grant Function Compute permissions to access other Alibaba Cloud services.
mytestrole
Access to VPC
Specify whether to allow the function to access Virtual Private Cloud (VPC) resources. For more information, see Configure network settings.
Yes
VPC
Specify the VPC. This parameter is required if you set Access to VPC to Yes. Create a new VPC or select the ID of an existing VPC that you want to access from the drop-down list.
fc.auto.create.vpc.1632317****
vSwitch
Specify the vSwitch. This parameter is required if Access to VPC is set to Yes. Create a new vSwitch or select the ID of an existing vSwitch from the drop-down list.
fc.auto.create.vswitch.vpc-bp1p8248****
Security Group
Specify the security group. This parameter is required if Access to VPC is set to Yes. Create a security group or select an existing security group from the drop-down list.
fc.auto.create.SecurityGroup.vsw-bp15ftbbbbd****
Allow Default NIC to Access Internet
Specify whether to allow the function to access the Internet through the default NIC. If you select No, the functions cannot access the Internet through the default NIC of Function Compute.
ImportantIf you use the static public IP address feature, you must set Allow Default NIC to Access Internet to No. Otherwise, the configured static public IP address does not take effect. For more information, see Configure static public IP addresses.
Yes
Logging
Specify whether to enable the logging feature. Valid values:
Enable: enables the logging feature. Execution logs of the function are persistently stored in Simple Log Service and can be used for code debugging, fault analysis, and data analysis.
Disable: does not enable the logging feature. Execution logs of the function cannot be stored and queried through Simple Log Service.
Enable
Environment Variables: Configure environment variables in the function runtime. For more information, see Configure environment variables.
Modify a function
After the function is created, if you need to change the image, you can modify the function on the Runtime tab of the Configurations page.
For more information about how to modify other configurations, such as environment variables and logging, see Function configuration.
Delete a function
Log on to the Function Compute console, click Functions, select a region, find the function that you want to delete, and then choose More > Delete in the Actions column to delete the function.
On the Function Details page, click Delete Function to delete the function.
More information
Function Compute provides four types of functions: event functions, web functions, task functions, and GPU functions for different scenarios. For information on how to select a function type based on scenarios, see Selection of methods to create functions.
In addition to the Function Compute console, you can also use the Function Compute API to manage functions. For more information, see Function.
If a function execution times out, troubleshoot the issue by referring to What do I do if the function execution times out and the error "Function time out after" is reported?
It may take a longer period of time to invoke functions that are not frequently used. For more information, see Why do functions that are infrequently used take a longer period of time to invoke? To mitigate cold starts, you can use provisioned instances. For more information, see How to keep instances alive to eliminate the impact of cold starts?
If you want to obtain the Alibaba Cloud Resource Name (ARN) of a function to locate corresponding resources in your code, see Obtain the ARN of a function.