All Products
Search
Document Center

Function Compute:Manage functions

Last Updated:Aug 24, 2023

Resources of Function Compute are scheduled and run by using functions. Functions must be deployed in services. In a 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. This topic describes the properties and runtimes of functions. This topic also describes how to create a function, update a function, and obtain the ARN of a function in the Function Compute console.

Prerequisites

You created a service in Function Compute. For more information, see Manage services.

Creates 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: processes HTTP requests or WebSocket requests. If you use a web scenario, we recommend that you select Use Custom Runtime.

    • Code: Configure the runtime environment and code-related information of the function.

      Parameter

      Description

      Examples

      Runtime

      Select a programming language, such as Python, Java, PHP, or Node.js. For more information about the runtimes supported by Function Compute, see Manage functions.

      Node.js14

      Code Upload Method

      Select a method to upload the function 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.

      • Upload ZIP: Select and upload the ZIP package that contains your code.

      • Upload JAR: Select and upload the JAR package that contains your code.

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

      • OSS: Specify the Bucket Name and Object Name parameters for the code to be uploaded.

      Note
      • If you set Code Upload Method to Use Sample Code, you do not need to modify Handler. 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. 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 must manually create a startup script named bootstrap in the root directory of the code. You can use the bootstrap script to start your program.

      npm run start

      Listener 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

    • In the Advanced Settings section, 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 capacity to memory capacity (in GB) must be set from 1:1 to 1:4.

      • If original resource plans are used to offset the current resource usage, Function Compute supports offset of vCPU and memory usage at a ratio of 2:3 (1 GB-second = 0.66 vCPU-seconds + 1 GB-seconds). Starting from November 3, 2022, Function Compute supports flexible vCPU-to-memory ratios. However, the value of vCPU must be increased at increments of 0.05. The value of 0.66 vCPU-seconds in the original conversion ratio is no longer supported. You can select 0.60 vCPU-seconds or 0.65 vCPU-seconds.

      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: 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.

      Note

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

      The temporary hard disk is consistent with the lifecycle of the underlying instance. After the instance is recycled by the system, the data on the hard disk is cleared. To persist the stored data, 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 value of a function instance. For more information, see Configure instance concurrency.

      10

      Execution Timeout Period

      The timeout period for the execution of the function. The default value of Execution Timeout Period is 60 seconds and the maximum value is 86,400 seconds.

      Note

      If the execution of the function is not complete before the specified timeout period ends, the function fails to be executed. If you want to apply a longer timeout limit, join the DingTalk group 11721331 to contact the technical support.

      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 Code Upload Method to Use Sample Code, you do not need to modify Handler. 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 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

    • In the Environment Variables section, configure the environment variables in the runtime environment 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 environment and other key parameters of the function. For more information, see Create a function.

    • Other Settings

      Parameter

      Description

      Reference

      Environment Variables

      Configure the 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 lifecycle

      Layers

      Select the names and versions of existing layers. Layers allow you to publish and deploy custom resources such as public libraries, runtime environments, 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 Alibaba Cloud Resource Name (ARN) to locate the corresponding Alibaba Cloud resources 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

Reference

Node.js 6

Node.js 6

Node.js runtime environments

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

Python runtime environments

Python 3

Python 3.6

Python 3.9

Python 3.9

Python 3.10

Python 3.10

PHP 7.2

PHP 7.2.7

PHP runtime environments

Java 11

Java 11

Java runtime environments

Java 8

Java 8

.NET Core 2.1

.NET Core 2.1

.NET Core runtime

.NET Core 3.1

.NET Core 3.1

Go 1.x

Go 1.8 or later

Go runtime environments

Custom Runtime

Custom runtime (Debian 9)

Custom runtime

Custom runtime (Debian 10)

Custom runtime (Debian 10)

Custom Container

N/A

Custom Container

Additional information

In addition to the Function Compute console, Function Compute allows you to use the following methods to manage functions: