To trigger a function with a specific event, such as a message from Object Storage Service (OSS) or RocketMQ, you can create an event function. You must write your function and program according to the interface defined by Function Compute. Function Compute schedules and runs resources at the function level. Each function is independent and does not affect other functions. This topic describes how to create and manage event functions in the console.
Create a function
Log on to the Function Compute console. In the navigation pane on the left, choose .
In the top menu bar, select a region. Then, on the Function List page, click Create Function.
In the dialog box that appears, select Event Function and then click Create Event Function.
On the Create Event Function page, set the following parameters and click Create.
Basic Configuration: Set the function specifications.
Parameter
Description
Example
Function Name
A unique name for the function. The function name must be unique within the same account and region and follow the naming rules.
myFunction
Specification Plan
Set the vCPU, Memory, and Disk specifications for the function as needed. After you set the specifications, the usage of each resource is calculated by multiplying the specification by the usage duration. For more information, see Billing overview.
NoteThe ratio of vCPU size (in cores) to memory size (in GB) must be set between 1:1 and 1:4.
All directories on the disk are writable. The disk space is shared.
The disk is available for the instance lifetime. After the system revokes the instance, the data on the disk is deleted. To store files with persistence, mount a NAS or OSS file system. For more information, see Configure a NAS file system and Configure Object Storage Service (OSS).
vCPU: 0.35 vCPU
Memory: 512 MB
Disk: 512 MB (Not billed. Function Compute provides a free quota of 10 GB of disk space.)
Elastic Configuration: Select an elastic mode.
Parameter
Description
Example
Minimum Instances
If your business is sensitive to latency, set **Minimum Instances** to 1 or higher. This pre-allocates resources and reduces cold start latency.
NoteIf you set **Minimum Instances** to 1 or higher, and no elastic policy for minimum instances is configured or valid for a period, the current number of minimum instances is the value you set here.
If you configure multiple elastic policies, the system calculates the Minimum Instances for each policy when it is triggered. The system then uses the highest value among the valid policies as the current Minimum Instances.
For more information, see How is the current number of minimum instances calculated?.
Enabled
Function Code: Configure the function's runtime and code.
Parameter
Description
Example
Runtime
Select Built-in Runtime and choose a language and version you are familiar with, such as Python, Java, PHP, or Node.js. For more information, see Function Compute runtimes.
To create a Web Function, select Custom Runtime. For more information, see Create a web function.
To create a GPU Function, select Custom Image. For more information, see Create a GPU function.
This topic uses Built-in Runtime as an example.
Code Upload Method
Select the method to upload code to Function Compute.
Use Sample Code: Select this option to create the function with the provided Hello World sample code. You can edit and test the code later on the Code tab of the function details page.
Upload A ZIP Package: Select and upload a ZIP package that contains your function code.
Upload A JAR Package: Select and upload a JAR package that contains your function code.
This applies only to the Java runtime.
Upload A Folder: Select and upload a folder that contains your function code.
Upload From OSS: Select the Bucket Name and File Name where your function code is stored.
Use Sample Code
Request Handler
Set the handler. The Function Compute runtime loads and calls your handler to process requests.
If you set Code Upload Method to Use Sample Code, you do not need to change the Handler. If you select another upload method, change the Handler as needed. Otherwise, an error occurs when the function is executed.
index.handler
Execution Timeout
Set the timeout period. The default Execution Timeout is 60 seconds. The maximum value is 86400 seconds.
60
Permissions, Network, and Storage: Configure the function's access role, network settings, and storage mounts.
Parameter
Description
Example
Function Role
The Function Compute platform uses this RAM role to generate temporary keys for accessing Alibaba Cloud resources and passes them to the code. For more information, see Use a function role to grant Function Compute permissions to access other Alibaba Cloud services.
mytestrole
Allow Access To VPC
Enable this to allow the function to access resources in a VPC. For more information, see Configure network settings.
Enabled
VPC
Required if you set Allow Access To VPC to Yes. Create a new VPC or select a VPC ID from the drop-down list.
fc.auto.create.vpc.1632317****
VSwitch
Required if you set Allow Access To VPC to Yes. Create a new vSwitch or select a vSwitch ID from the drop-down list.
fc.auto.create.vswitch.vpc-bp1p8248****
Security Group
Required if you set Allow Access To VPC to Yes. Create a new security group or select a security group from the drop-down list.
fc.auto.create.SecurityGroup.vsw-bp15ftbbbbd****
Allow Default NIC To Access Public Network
Allow the function to access the public network through the default network interface card.
ImportantWhen you use a static public IP address, you must disable Allow Default NIC To Access Public Network. Otherwise, the configured static public IP address does not take effect. For more information, see Configure a static public IP address.
Enabled
Mount NAS File System
Mount a NAS file system to the function for persistent storage of shared data, such as models shared by multiple inference functions. For more information, see Configure a NAS file system.
If you select automatic configuration, the system uses an existing General-purpose NAS file system named Alibaba-Fc-V3-Component-Generated. If a qualifying NAS file system does not exist in your account, the system creates one.
Enabled
Mount OSS Object Storage
Mount an OSS bucket to the function for persistent storage of logs, business files, and other data. For more information, see Configure Object Storage Service (OSS).
Enabled
Logs And Tracing Analysis
Parameter
Description
Example
Log Feature
Persistently save the function's execution logs to Simple Log Service. This helps with code debugging, troubleshooting, and data analytics. For more information, see Configure the logging feature.
Automatic Configuration: Automatically selects a log project that starts with
serverless-<region_id>.Only one such log project is created in each region. If the system finds that this log project already exists in the current region, it uses the existing project.
Custom Configuration: Manually specify the destination Log Project and Logstore.
Enabled
More Configurations
Parameter
Description
Example
Time Zone
Select the time zone for the function. This automatically adds the TZ environment variable to the function with the selected time zone as its value.
UTC
Tags
Set tags for the function to group and manage functions. You must set both a tag key and a tag value.
key : value
Resource Group
Select the resource group for the function. Use resource groups to manage your functions in groups.
Default Resource Group
Environment Variables
Use environment variables to flexibly adjust the function's behavior without changing the code. For more information, see Configure environment variables.
{ "BUCKET_NAME": "MY_BUCKET", "TABLE_NAME": "MY_TABLE" }
Edit a function
You can edit, import, or export function code. To change other configuration items, see Configure a function.
On the Function Details page, you can change the function code on the Code tab. If the branch on the left indicates a change (① in the figure), you must first click Deploy Code to apply your changes. Then, click Test Function.

You can also export your code as a backup or upload new code for deployment.


Delete a function
Log on to the Function Compute console. On the Function List page, find the function you want to delete and click Delete in the Actions column. In the dialog box that appears, confirm that the function has no attached resources, such as triggers or elastic policies for minimum instances. Then, confirm the deletion.
Get the function ARN
An Alibaba Cloud Resource Name (ARN) is used to identify an Alibaba Cloud resource in your code. You can obtain the ARN of a function to reference it.
Log on to the Function Compute console. In the navigation pane on the left, choose .
In the top menu bar, select a region. Then, on the Function List page, click the name of the function.
On the Function Details page, click Copy ARN on the right to obtain the ARN of the target function.

References
Function Compute provides four types of functions for different usage scenarios: event functions, web functions, task functions, and GPU functions. For more information about how to select a function type for your usage scenario, see Technical selection guide.
In addition to the console, Function Compute provides other ways to manage functions, such as by calling APIs or using the Serverless Devs tool. For more information, see CreateFunction and Serverless Devs Quick Start.
For information about what to do when a function execution times out, see What do I do if a function execution times out and reports 'Function time out after'?.
Infrequently invoked functions have longer invocation times. For more information, see Why do functions that are invoked infrequently have longer invocation times?. To eliminate the cold start latency of elastic instances, set the minimum number of instances to 1 or higher.