All Products
Search
Document Center

Function Compute:Manage functions

更新時間:Oct 31, 2024

Resources of Function Compute are scheduled and run based on 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 manage functions. For example, you can create functions, modify function configurations, and obtain Alibaba Cloud Resource Names (ARNs) of functions.

Before you start

Create a service

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 a 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 HTTP requests or WebSocket requests. In web scenarios, we recommend that you select Use Custom Runtime.

    • In the Code section, 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. For more information about the runtimes that are supported by Function Compute, see Runtimes that are supported by Function Compute.

      Node.js14

      Code Upload Method

      Select a method to upload function code to Function Compute.

      • Use Sample Code: Select 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 package that contains your code.

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

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

      • OSS: Specify the Bucket Name and Object Name parameters for your function code.

      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 you run the function.

      • If you set Runtime 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.

      Configure 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. The bootstrap script is used to start your program.

      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 instance information and the function execution timeout period.

      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.

      Note

      The 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 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 of this size. Function Compute provides you with a free disk capacity 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 stored data, you can use 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 instance concurrency. For more information, see Configure instance concurrency.

      10

      Execution Timeout Period

      Specify the timeout period of a function execution. The default value of Execution 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. This parameter is not required if you select Use Custom Runtime or Use Container Image.

      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 you run the function.

      index.handler

      Time Zone

      Specify 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

    • Environment Variables: Configure environment variables for the runtime of your 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, Size of Temporary Disk, and Instance Concurrency parameters.

    • Environment Information

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

    • Other settings

      Parameter

      Description

      Reference

      Environment Variables

      Configure environment variables for the runtime of the function.

      Environment variables

      Instance Lifecycle Hook

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

      Function instance lifecycle

      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 needed 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

Node.js

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

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

Java 11

Java 11

Java

Java 8

Java 8

.NET Core 3.1

.NET Core 3.1

.NET Core

Go 1.x

Go 1.8 or later

Go

Custom Runtime

Custom runtime (Debian 9)

Overview

Custom runtime (Debian 10)

Custom runtime (Debian 10)

Custom Container

None

Custom Container

References