A function is the unit for system scheduling and operation in Function Compute. A function belongs to a service. In the service, you can create multiple functions that share some identical settings, such as service authorization and log settings. These functions are independent from each other. This topic describes the properties and runtime environments of functions, and how to create, configure, and delete functions in the Function Compute console.

Prerequisites

Create a Service

Supported runtime environments

Runtime environment Description References
Node.js 6.x Node.js 6.x Node.js runtime environments
Node.js 8.x Node.js 8.x
Node.js 10.x Node.js 10.x
Node.js 12.x Node.js 12.x
Node.js 14.x Node.js 14.x
Python 2.7 Python 2.7 Python runtime environments
Python 3 Python 3.6
Python 3.9 Python 3.9
PHP 7.2 PHP 7.2.7 PHP runtime environment
Java 11 Java 11 Java runtime environments
Java 8 Java 8
.NET Core 2.1 .NET Core 2.1 .NET Core runtime environment
Go 1.x Go 1.8 or later Runtime environment
Custom Runtime N/A Custom Runtime
Custom Container N/A Custom Container

Create a function

  1. Log on to the Function Compute console.
  2. In the left-side navigation pane, click Services and Functions.
  3. In the top navigation bar, select the region where the service resides.
  4. On the Services page, click the target service.
  5. On the Functions page, click Create Function.
  6. On the Create Function page, select a method to create the function.
    In this example, Start from Scratch is selected. For more information, see the following topics:
  7. In the Basic Settings section, set the parameters and click Create. sc_create_function_v2.png
    The following table describes the parameters in the Display Content Column dialog box.
    Parameter Required? Title bar Example
    Parameter No The name of the function. It must start with a letter and can contain digits, letters (case-sensitive), underscores (_), and hyphens (-). It can be up to 64 characters in length.
    Note If you do not specify a name, the Function Compute is automatically created for you.
    Function
    Runtime environment Yes Select a language, such as Python, Java, PHP, or Node.js. For more information about the runtime environments supported by Function Compute, see Function overview. Node.js 12.x
    Function trigger mode Yes Select a function trigger mode.
    • Trigger by Event: triggers function execution through timers and triggers of other Alibaba Cloud services.
    • Triggered by HTTP Request: You can send an HTTP request to trigger function execution, which is suitable for scenarios such as quickly building Web services.
    Triggered by events
    Network Type Yes The instance category for the function. Valid values:
    • Elastic Instance
    • Performance Instance
    For more information, see Instance types and instance modes.
    Elastic Instance
    Memory specification Yes The memory that is required to execute the function.
    • Select Input: Select the required memory from the drop-down list.
    • Manual Input: Click Manually Enter Memory Size to customize the memory size of the function. The memory specifications are described as follows:
      • Elastic Instance: Valid values: [128, 3072]. Unit: MB.
      • Performance Instances: Valid values: [4 to 32]. Unit: GB.
      Note The memory value must be a multiple of 64 MB.
    512 MB
    After the function is created, you can view the created function on the Function Management page.

Obtain the ARN of a function

  1. Log on to the Function Compute console.
  2. In the left-side navigation pane, click Services and Functions.
  3. In the top navigation bar, select the region where the service resides.
  4. On the Services page, click the target service.
  5. On the Functions page, click the name of the function that you want to manage.
  6. Find the desired function. Go to the function details page and copy the Alibaba Cloud Resource Name (ARN) of the function in the Overview section.
    You can use ARNs to find corresponding Alibaba Cloud resources in code.

Update a function

  1. Log on to the Function Compute console.
  2. In the left-side navigation pane, click Services and Functions.
  3. In the top navigation bar, select the region where the service resides.
  4. On the Services page, click the target service.
  5. On the Functions page, find the function that you want to manage and click Configure in the Actions column.
  6. On the Modify Function Settings page, modify the configuration items based on your business requirements and click Save.
    • Optional: Basic Settings

      Configure the basic information of the function. You can modify only the Description, Instance Category, and Memory Capacity parameters.

      Parameter Description
      Description Enter a description for the function. The description helps you identify the purpose of the function.
      Instance Category The instance category for the function. Valid values:
      • Elastic Instance
      • Performance Instance
      For more information, see Instance types and instance modes.
      Memory Capacity The memory that is required to execute the function.
      • Select Input: Select the required memory from the drop-down list.
      • Manual Input: Click Manually Enter Memory Size to customize the memory size of the function. The memory specifications are described as follows:
        • Elastic Instance: Valid values: [128, 3072]. Unit: MB.
        • Performance Instances: Valid values: [4 to 32]. Unit: GB.
        Note The memory value must be a multiple of 64 MB.
      Notice When you modify the Instance Category parameter, take note of the following rules:
      • You can change the value from Elastic Instance to Performance Instance or from Performance Instance to Elastic Instance.
      • When you change the value from Performance Instance to Elastic Instance, the instance specifications are downgraded. In this case, Function Compute detects the switchover risk and automatically downgrades the memory size.
    • Optional:Environment Information

      Configure the runtime environment and other key parameters of the function.

      Parameter Description
      Runtime Environment Select a language, such as Python, Java, PHP, or Node.js. For more information about the runtime environments supported by Function Compute, see .
      Request Handler The function handler, which is in the format of [File name].[Function name].
      Notice If you set Runtime Environment to Custom Runtime, you cannot set the function handler.
      Startup Command (public preview) This parameter is required only when you set Runtime Environment to Custom Runtime. Configure the startup command for the custom bootstrap file. You must enter an absolute path. Example: /code/Bootstrap. Configure a custom startup command and the related parameters
      Startup Parameters (public preview) This parameter is required only when you set Runtime Environment to Custom Runtime. Configure the list of parameters received by the custom bootstrap file.
      Listener Port This parameter is required only when you set Runtime Environment to Custom Runtime. Set the value of this parameter to the port on which the custom HTTP server listens. For more information about how to configure the listening port of the HTTP server, see Configuration requirements on an HTTP server.
      Execution Timeout Period The timeout period for the execution of the function. The default value is 60 seconds. The maximum value is 86400 seconds.
      Note If the execution time of the function exceeds the specified timeout period, the function fails to be executed. If you want to specify a longer timeout period, submit a ticket.
      Instance Concurrency The number of requests that can be concurrently processed by a single instance. For more information, see Set the request concurrency in a single instance.
      Notice This parameter is invalid for the Python and PHP runtime environments.
    • Optional:Other configurations
      Parameter Description References
      Lifecycle Function The lifecycle functions of the function, including the initializer function, PreFreeze function, and PreStop function. Function instance lifecycle
      Layers The name and version of an existing layer. Layers allow you to publish and deploy custom resources such as public libraries, runtime environments, and function extensions. Use layers in functions
      Environment Variables The environment variables in the runtime environment of the function. Environment variables
      DNS Configuration 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

Delete a function

  1. Log on to the Function Compute console.
  2. In the left-side navigation pane, click Services and Functions.
  3. In the top navigation bar, select the region where the service resides.
  4. On the Services page, click the target service.
  5. On the Functions page, find the function that you want to delete and choose More > Delete in the Actions column.
  6. Delete the function.
    • If no trigger is configured for the function or the triggers configured for the function are deleted, click Delete in the message that appears. db_delete_function_without_trigger
    • If triggers are configured for the function and the triggers are not deleted, select I want to delete the preceding resources and the function in the dialog box that appears. Then, click Delete. db_delete_function_with_trigger

Additional information

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