Resources of Function Compute are scheduled and run based on functions. Functions are independent of each other. If you want to write a program by following interfaces defined by Function Compute, select Event Function when you create a function.
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 Event 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 programming 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. The following table describes the parameters.
Parameter
Description
Example
Specifications
Configure 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 (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 of 512 MB.
10 GB: You are charged based on a 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 changes with the 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 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 of a function execution. The default timeout period is 60 seconds, and the maximum value is 86,400 seconds.
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
This parameter is required if you set the Access to VPC parameter 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
This parameter is required if you set the Access to VPC parameter 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
This parameter is required if you set the Access to VPC parameter 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. The stored logs can be used for purposes such as 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.
Update the function: After the function is created, you can modify its configurations on the Configurations tab based on your business requirements.
Delete the function: You can also delete the function in the function list or on the function details page if you no longer need the function
Obtain the ARN of the function
You can use an Alibaba Cloud Resource Name (ARN) to locate the corresponding Alibaba Cloud resource in code. You can obtain the ARN of a function for easy reference.
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 the function that you want to update.
On the function details page, click the Configurations tab. In the Basic Configurations tab, view and copy the ARN of the function.
Additional information
In addition to the Function Compute console, Function Compute also allows you to use API operations to manage functions. For more information, see Function.
If the function timeout period elapses, see What do I do if the function execution times out and the error "Function time out after" is reported?
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?