All Products
Search
Document Center

Function Compute (2.0):Manage functions

Last Updated:Jun 05, 2024

Resources of Function Compute are scheduled and run by using functions. In a Function Compute service, you can create multiple functions that share some identical settings, such as service authorization and log settings. These functions are independent of each other. In the Function Compute console, you can perform operations on functions. For example, you can create functions, modify function configurations, and obtain Alibaba Cloud Resource Names (ARNs) of functions.

Prerequisites

A service is created in Function Compute. For more information, see the "Create a service" section of the Manage services topic.

Create a function

  1. Log on to the Function Compute console. In the left-side navigation pane, click Services & Functions.

  2. In the top navigation bar, select a region. On the Services page, click the desired service.

  3. On the Functions page, click Create Function.
  4. On the Create Function page, select a method to create the function, configure the following parameters, and then click Create.

    Note

    In this example, Use Built-in Runtime and Use Custom Runtime are used. If the runtimes provided by Function Compute cannot meet your business requirements, you can select Use Container Image to create a function. For more information, see Create a custom container function.

    • Basic Settings: Configure the basic information of the function, including Function Name and Handler Type. Handler Type can be set to one of the following values:

      • Event Handler: triggers the function by using a timer, calling API operations, using SDKs, or using triggers integrated with other Alibaba Cloud services.

      • HTTP Handler: triggers function execution by sending an HTTP request or creating a WebSocket connection. If you use a web scenario, we recommend that you select Use Custom Runtime.

    • 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. For more information about the runtimes that are supported by Function Compute, see Supported function runtime environments.

      Node.js14

      Code Upload Method

      Select a method to upload the function code to Function Compute.

      • Use Sample Code: Select the sample code provided by Function Compute to create a function based on your business requirements.

      • Upload ZIP: Select and upload a .zip file that contains function code.

      • Upload JAR: Select and upload a .jar file that contains function code.

      • Upload Folder: Select and upload the folder that contains function code.

      • OSS: Specify the Bucket Name and Object Name parameters for function code that you want to upload.

      Note
      • If you set the Code Upload Method parameter to Use Sample Code, retain the 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 is run.

      • If you set the Runtime parameter to Java 8 or Java 11, you can select only Use Sample Code, Upload JAR, or OSS to upload function code. For other runtimes, you can select Use Sample Code, Upload ZIP, Upload Folder, or OSS.

      Use Sample Code

      Startup Command

      Note

      You must configure this parameter only if you select Use Custom Runtime to create a function.

      The startup command of the program. If you do not configure the startup command, you need to manually create a startup script named bootstrap in the root directory of function code. You can start your program by using this script.

      npm run start

      Listening Port

      Note

      You must configure this parameter only if you select Use Custom Runtime to create a function.

      Specify the port on which the HTTP server in your code listens.

      9000

    • Advanced Settings: Configure the instance information and the function execution timeout period.

      Parameter

      Description

      Example

      Specifications

      Configure the vCPU Capacity and Memory Capacity parameters based on your business requirements. For more information about the billing of resources, see Billing overview.

      Note

      The ratio of vCPU to memory capacity (in GB) is 1: N. N must be a value that ranges from 1 to 4.

      0.35 vCPUs, 512 MB

      Size of Temporary Disk

      Specify the size of the hard disk used to temporarily store files based on your business requirements.

      Valid values:

      • 512 MB (default): You are not charged for using a temporary disk less than 512 MB in 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.

      Note

      Data can be written to all directories in the temporary hard disk. The directories share the space of the temporary hard disk.

      The lifecycle of the temporary hard disk is consistent with that of the underlying instance. After the instance is recycled by the system, the data on the hard 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

      Instance Concurrency

      Specify the concurrency to process requests for instances. For more information, see Configure instance concurrency.

      10

      Execution Timeout Period

      Specify the timeout period for the execution of the function. 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. If you select Use Custom Runtime or Use Container Image, you do not need to specify this parameter.

      Note

      If you set the Code Upload Method parameter to Use Sample Code, retain the 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 is run.

      index.handler

      Time zone

      Select the time zone of your 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

    • In the Environment Variables section, configure the environment variables in the runtime of the function. For more information, see Environment variables.

    • In the Trigger Configurations section, configure a trigger for the function based on your business requirements. You can use the trigger to trigger the function. For more information, see Manage triggers.

Update a function

  1. Log on to the Function Compute console. In the left-side navigation pane, click Services & Functions.

  2. In the top navigation bar, select a region. On the Services page, click the desired service.

  3. On the Functions page, find the function that you modify and click Configure in the Actions column.
  4. On the Modify Function Settings page, modify parameters based on your business requirements and click Save.

    • Basic Settings

      Configure the basic information about the function. You can modify the Description, Specifications, Disk Capacity, and Instance Concurrency parameters.

    • Environment Information

      Configure the runtime and other key parameters of the function. For more information, see Create a function.

    • Other Settings

      Parameter

      Description

      References

      Environment Variables

      Configure environment variables in the runtime of the function.

      Environment variables

      Instance Lifecycle Hook

      Configure the lifecycle hooks for the instances. Lifecycle hooks include Initializer Hook, PreFreeze Hook, and PreStop Hook.

      Function instance lifecycles

      Layers

      Select the name and version of an existing layer. Layers allow you to publish and deploy custom resources such as public libraries, runtimes, and function extensions.

      Create a custom layer

      DNS Settings

      Configure the custom domain name system (DNS) settings. Function Compute generates the resolv.conf file based on the DNS settings.

      Configure custom DNS settings for functions

Note

You can delete a function that is no longer used based on your business requirements.

Obtain the ARN of a function

You can use an ARN to locate the corresponding Alibaba Cloud resource in code. You can obtain the ARN of a function for easy reference.

  1. Log on to the Function Compute console. In the left-side navigation pane, click Services & Functions.

  2. In the top navigation bar, select a region. On the Services page, click the desired service.

  3. On the Functions page, click the name of the function whose ARN you want to obtain.

  4. On the function details page, click the Configurations tab. In the Basic Settings section, view and copy the ARN of the function.

Runtimes that are supported by Function Compute

Runtime

Description

References

Node.js 6

Node.js 6

Overview

Node.js 8

Node.js 8

Node.js 10

Node.js 10

Node.js 12

Node.js 12

Node.js 14

Node.js 14

Node.js 16

Node.js 16

Python 2.7

Python 2.7

Overview

Python 3

Python 3.6

Python 3.9

Python 3.9

Python 3.10

Python 3.10

PHP 7.2

PHP 7.2.7

Overview

Java 11

Java 11

Overview

Java 8

Java 8

.NET Core 3.1

.NET Core 3.1

Overview

Go 1.x

Go 1.8 or later

Runtime environment

Custom Runtime

Custom runtime (Debian 9)

Overview

Custom runtime (Debian 10)

Custom runtime (Debian 10)

Custom Container

None

Overview

Additional information