Function Compute provides you with a fully managed, ready-to-use, and observable platform for large-scale task processing. You can create task functions, for which the task mode is enabled by default, in the Function Compute console. You can submit, view, stop, and retry asynchronous requests by using the task mode.
Procedure
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 Task Function, configure the following parameters, and then click Create.
Basic Settings: Configure Function Name.
Code: Configure the runtime and code-related information of the function.
Parameter
Description
Example
Runtime
Select a language, such as Python, Java, PHP, or Node.js.
Node.js 16
Code Upload Method
Specify how to upload code to Function Compute.
Use Sample Code: You can select the sample code provided by Function Compute to create a function based on your business requirements. This is the default method.
Upload ZIP: Select and upload a .zip file that contains your function code.
Upload Folder: Select and upload the folder that contains your function code.
OSS: Upload code from an Object Storage Service (OSS) bucket. In this case, you must specify the Bucket Name and Object Name parameters.
Use Sample Code
In the Advanced Settings section, configure instance settings and other items such as the function execution timeout period.
Parameter
Description
Example
Specifications
Configure instance specifications, such as vCPU Capacity and Memory Capacity based on your business requirements. For more information about billing of resources, see Billing overview.
NoteThe ratio of vCPU capacity to memory capacity (in GB) must be set from 1:1 to 1:4.
0.35 vCPUs, 512 MB
Size of Temporary Disk
Specify the size of the disk used to temporarily store files based on your business requirements.
Valid values:
512 MB: the default value. 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 the disk size of 9.5 GB.
NoteData shares the space of the temporary disk and can be written to all directories in the disk.
The size of the temporary disk is consistent with lifecycles of underlying instances. After an instance is recycled by the system, the corresponding data on the disk is cleared. To persist files, you can use Apsara File Storage NAS (NAS) or 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 of a function execution. The default timeout period is 60 seconds, and the maximum value is 86,400 seconds.
NoteIf the execution of the function times out, the function fails to be executed. If you require a longer timeout limit, join the DingTalk group 11721331 for technical support.
60
Handler
Specify the handler of the function. The Function Compute runtime loads and invokes the handler to process requests.
NoteIf you set the Code Upload Method parameter to Use Sample Code, retain the default value of the Handler parameter. If you select another code upload method, you must modify Handler based on your business requirements. Otherwise, an error is reported when the function runs.
index.handler
Time Zone
Select the time zone of the function. After you configure the time zone of the function, the environment variable TZ is automatically added to the function. The value is the time zone that you configure.
UTC
Function Role
Specify the RAM role of the function. Function Compute uses this role to generate a temporary AccessKey pair for accessing your Alibaba Cloud resources and passes the AccessKey pair 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 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 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 you set Access to VPC to Yes. Create a 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 you set Access to VPC 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 network interface controller (NIC). If you select No, the function cannot access the Internet through the default NIC of Function Compute.
ImportantIf you use a static public IP address, 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: Function execution logs are persistently stored in Simple Log Service for code debugging, fault analysis, and data analysis.
Disable: You cannot use Simple Log Service to store or query function execution logs.
Enable
In the Environment Variables section, configure environment variables for the runtime of the function. For more information, see Configure environment variables.
After the function is created, go to the function details page. On the Code tab, you can modify, deploy, and test the function.
NoteUpdate the function: After the function is created, you can modify the configurations on the Configuration tab based on your business requirements.
Delete the function: You can also delete the function on the function list or function details page if you no longer need the function
After the function is created, the task mode is enabled by default in the Asynchronous Mode Configurations tab of the Configurations page.
More information
After a task function is created, the task mode is enabled by default. You can manage your asynchronous invocations by using the task mode. For more information, see Task management.
You can also enable the asynchronous task mode for an existing function. For more information, see Enable the asynchronous task mode for an existing function.
Aside from the Function Compute console, you can also call an API operation to initiate asynchronous tasks. For more information, see InvokeFunction.
If the execution of a function times out, see FAQ about function management.
If it takes a long time to invoke a function that is not frequently used, see Why do functions that are infrequently used take a longer period of time to invoke? To mitigate the impact of cold starts, you can use provisioned instances. For more information, see How to keep instances alive to eliminate the impact of cold starts?