Function Compute uses functions to schedule and run resources. 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 runtime environments of functions. This topic also describes how to create a function, update a function, and obtain the Alibaba Cloud Resource Name (ARN) of a function in the Function Compute console.

Runtime environments supported by Function Compute

Runtime environmentDescriptionReferences
Node.js 6Node.js 6Node.js runtime environments
Node.js 8Node.js 8
Node.js 10Node.js 10
Node.js 12Node.js 12
Node.js 14Node.js 14
Node.js 16Node.js 16
Python 2.7Python 2.7Python runtime environments
Python 3Python 3.6
Python 3.9Python 3.9
PHP 7.2PHP 7.2.7PHP runtime environments
Java 11Java 11Java runtime environments
Java 8Java 8
.NET Core 2.1.NET Core 2.1.NET Core runtime environments
.NET Core 3.1.NET Core 3.1
Go 1.xGo 1.8 or laterGo runtime environments
Custom RuntimeNoneCustom Runtime
Custom ContainerNoneCustom Container

Before you begin

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

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 This topic uses the Use Built-in Runtime and Use Custom Runtime methods as examples. If the environments provided by Function Compute do not meet your business requirements, you can select Use Container Image to deploy the function. For more information, see Create a custom container function.
    • In the Basic Settings section, configure the basic information about the function, including the function name and the handler type. Handlers are classified into the following types:
      • Event Handler: triggers the execution of 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. For a web scenario, we recommend that you select Use Custom Runtime.
    • In the Code section, configure the runtime environment and code-related information of the function.
      ParameterDescription
      RuntimeSelect a programming language, such as Python, Java, PHP, or Node.js. For information about the runtime environments that are supported by Function Compute, see the "Runtime environments supported by Function Compute" section of this topic.
      Code Upload MethodSelect a method to upload function code to Function Compute.
      • Use Sample Code: Use the sample code provided by Function Compute to create a function. This is the default method.
      • Upload ZIP: Select and upload the ZIP package that contains your code.
      • Upload Code in JAR Package: 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 that is to be uploaded.
      Note If you set the Runtime parameter to Java 8 or Java 11, you can select only Use Sample Code, Upload Code in JAR Package, or OSS. For other runtime environments, you can select Use Sample Code, Upload ZIP, Upload Folder, or OSS.
      Startup Command
      Note This parameter is required only when 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.
      Listening Port
      Note This parameter is required only when you select Use Custom Runtime to create a function.
      Specify the port on which the HTTP server in your code listens.
    • In the Advanced Settings section, configure the instance information and the function execution timeout period.
      ParameterDescription
      SpecificationsConfigure the vCPU Capacity and Memory Capacity parameters based on your business requirements. For information about the billing for resource usage, see Billing overview.
      Note
      • The ratio of vCPU capacity to memory capacity (in GB) ranges from 1:1 to 1:4.
      • When 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 by 0.05. The value of 0.66 vCPU-seconds in the original conversion ratio is no longer applicable. You can select 0.60 vCPU-seconds or 0.65 vCPU-seconds.
      Disk CapacitySelect a disk capacity based on your business requirements.
      Valid values:
      • 512 MB: the default value. Function Compute provides you with a free disk usage of up to 512 MB.
      • 10 GB: You are charged based on a disk usage of 9.5 GB.
      Instance ConcurrencySpecify the concurrency of the function instance. For more information, see Configure instance concurrency.
      Execution Timeout PeriodThe 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 specify a longer timeout period, join the DingTalk group 11721331 to contact Function Compute technical support.
      HandlerSpecify the handler of the function. The Function Compute runtime loads and invokes the handler to process requests. This parameter is not required if you create a function by selecting Use Custom Runtime.
      Time ZoneSelect 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.
    • 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. You can use the trigger to trigger the execution of the function. For more information, see Trigger management

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 the 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 configurations
      ParameterDescriptionReference
      Environment VariablesConfigure the environment variables in the runtime environment of the function. Environment variables
      Instance Lifecycle HookConfigure the lifecycle hooks for the instances. Lifecycle hooks include Initializer Hook, PreFreeze Hook, and PreStop Hook. Function instance lifecycle
      LayersSelect 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 ConfigurationConfigure 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 ARNs to locate 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 for which you want to obtain the ARN.
  4. On the Configurations tab of the function details page, view and copy the ARN of the function in the Basic Settings section.

Additional information

Aside from the Function Compute console, you can use the following methods to manage functions in Function Compute: