Create a web function
To run applications built on popular frameworks like Flask, Express, or Spring Boot, or to migrate existing framework-based applications to Function Compute, you can create a web function. In Function Compute, resources are scheduled and run on a per-function basis. Each function is independent and isolated. This topic explains how to create and manage web functions in the Function Compute console.
Create a function
-
Log in to the Function Compute console. In the left-side navigation pane, choose .
-
In the top menu bar, select a region. On the Functions page, click Create Function.
-
In the dialog box that appears, select Web Function, and then click Create Web Function.
-
On the Create Web Function page, configure the following settings, and then click Create.
-
Basic Configurations: Set the function specifications and instance settings.
Parameter
Description
Example
Function Name
A unique identifier for the function. The name must be unique within a region for your Alibaba Cloud account and follow the naming conventions.
myFunction
Specifications
Set the vCPU, Memory, and Disk specifications for the function based on your workload. You are billed for resource usage based on these specifications and the execution duration. For more information, see Billing overview.
Note-
The ratio of vCPU size (in cores) to memory size (in GB) must be between 1:1 and 1:4.
-
All directories on the disk are writable, and the disk space is shared among all function instances.
-
Data on the disk is ephemeral and is lost when the instance is reclaimed. To persist files, mount a NAS file system or an OSS bucket. For more information, see Configure a NAS file system and Configure OSS.
-
vCPU: 0.35 vCPU
-
Memory: 512 MB
-
Disk: 512 MB (Not billed. Function Compute provides a free quota of 10 GB for disk space.)
Instance Concurrency
Set the number of concurrent requests that a single function instance can process. For more information, see Configure concurrency per instance.
20
-
-
Scaling Policy: Select an elasticity mode.
Parameter Description Example Minimum instances The minimum number of instances to keep running. Set to 1or higher to pre-warm instances and reduce cold start latency for latency-sensitive workloads. If no elastic policy is configured or no valid policy is in effect, the effective minimum is the value you set here. If multiple elastic policies are active, Function Compute uses the highest value among them as the effective minimum. For details, see Instance scaling rules.1 -
Code: Configure the function's runtime and code settings.
Parameter
Description
Example
Runtime
We recommend that you select Custom Runtime and choose a programming language or framework that you are familiar with. For more information, see Code development overview.
-
To create an Event Function, select Built-in Runtimes. For more information, see Create an event function.
-
To create a GPU Function, select Custom Container. For more information, see Create a GPU-accelerated function.
Code Upload Method
Select a method to upload your code.
-
Use Sample Code: The default option. You can select sample code provided by Function Compute based on your business requirements.
-
Upload ZIP: Select and upload a ZIP package that contains your function code.
-
Upload Folder: Select and upload a folder that contains your function code.
-
OSS: Specify the Bucket Name and Object Name of the function code package in OSS.
Use Sample Code
Startup Command
The startup command of the application. If you do not specify a startup command, you must manually create a startup script named bootstrap in the root directory of your code. The application starts by using this script.
npm run start
Listening Port
The port on which the HTTP server in your code listens.
9000
Execution Timeout Period
The timeout period for function execution. The default value of Execution Timeout Period is 60 seconds, and the maximum value is 86,400 seconds.
60
-
-
Permissions, network, and storage: Configure the function's access role, network, and storage mounts.
Parameter Description Example Function role A RAM role that Function Compute uses to generate temporary credentials for accessing other Alibaba Cloud services. For setup details, see Grant Function Compute permissions to access other Alibaba Cloud services. mytestroleAccess to VPC Enable to allow the function to access resources inside a virtual private cloud (VPC). For configuration details, see Configure a network. Enabled VPC Required when Access to VPC is enabled. Select an existing VPC or create a new one. fc.auto.create.vpc.1632317****vSwitch Required when Access to VPC is enabled. Select an existing vSwitch or create a new one. fc.auto.create.vswitch.vpc-bp1p8248****Security group Required when Access to VPC is enabled. Select an existing security group or create a new one. fc.auto.create.SecurityGroup.vsw-bp15ftbbbbd****Allow default NIC to access internet Controls whether the function can reach the internet through its default network interface controller (NIC). Enabled Mount a NAS file system Mount a NAS file system to persistently share data across functions, such as model files used by multiple inference functions. With automatic configuration, the system uses or creates a General-purpose NAS file system named Alibaba-Fc-V3-Component-Generated. For details, see Configure a NAS file system.Enabled Mount OSS Mount an OSS bucket to persistently store logs, business files, and other data. For details, see Configure Object Storage Service (OSS). Enabled ImportantWhen using a static public IP address, disable Allow default NIC to access internet. Otherwise, the static public IP address does not take effect. For details, see Configure a static public IP address.
-
Log monitoring and tracing
Parameter Description Example Log monitoring Persist function execution logs to Simple Log Service for debugging, fault analysis, and data analytics. Automatic Configuration uses or creates a log project named serverless-<region_id>(one per region). Custom Configuration lets you specify the Log Service Project and Logstore. For details, see Configure the logging feature.Enabled -
More configurations
Parameter Description Example Time zone The time zone for the function. Setting this adds a TZenvironment variable with the selected value.UTCTag Tags for grouping and managing functions. Each tag requires a key and a value. For details, see Function tags. key : valueResource group The resource group the function belongs to. For details, see Resource groups. Default Resource Group Environment variables Key-value pairs injected into the function's execution environment, letting you change function behavior without modifying code. For details, see Configure environment variables. {"BUCKET_NAME": "MY_BUCKET", "TABLE_NAME": "MY_TABLE"}
-
Edit a function
On the Function Details page, use the Code tab to modify your function code directly in the console. You can also export code as a backup or upload new code.
If the left panel shows uncommitted changes, click Deploy before clicking Test Function to apply your changes.
To export or upload code:
On the Function Details page, click the Code tab. Then click Export Function in the upper-right corner and select Export Function Code from the dropdown menu.
On the Function Details page, click the Code tab. Then click Upload Code in the upper-right corner and select an upload method from the dropdown menu: Upload ZIP, Upload Folder, or OSS.
For other configuration changes such as instance specifications and scaling, see Function instance specifications and elastic configurations.
Delete a function
-
Log on to the Function Compute console. In the left navigation pane, choose Function Management > Function.
-
Locate the function and click Delete Function in the Actions column.
-
In the confirmation dialog, verify that the function has no attached resources (such as triggers or minimum-instance elastic policies), then confirm the deletion.
Get the ARN of a function
An Aliyun Resource Name (ARN) uniquely identifies an Alibaba Cloud resource and lets you reference functions from code or other services.
-
Log on to the Function Compute console. In the left navigation pane, choose Function Management > Function.
-
In the top menu bar, select a region. Click the target function.
-
On the Function Details page, click Copy ARN on the right.
Related topics
-
Function Compute provides four function types for different use cases: event functions, web functions, task functions, and GPU-accelerated functions. For guidance on how to choose a function type, see Technical selection guide.
-
Besides the console, you can also manage functions in Function Compute by using APIs or the Serverless Devs tool. For more information, see CreateFunction and Serverless Devs quick start.
-
If a function execution times out, see What do I do if a "Function time out after..." error is reported?.
-
Infrequently invoked functions may have longer invocation times. For details, see Why do infrequently used functions have longer invocation times?. To eliminate the impact of cold start latency on elastic instances, set the minimum number of instances to 1 or higher.