All Products
Search
Document Center

Function Compute:Manage functions

Last Updated:Feb 28, 2024

Resources of Function Compute are scheduled and run based on functions. Functions in Function Compute 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.

Create a function

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

  2. In the top navigation bar, select a region. On the Functions page, click Create Function.

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

    Note

    In this topic, Event Function and Web Function are used as examples. If the environment provided by Function Compute cannot meet your business requirements, you can select Container Images to deploy functions. For more information, see Create a Custom Container function.

    • Basic Settings: Configure Function Name.

    • 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, see Runtimes supported by Function Compute.

      Node.js 16

      Code Upload Method

      Specify how to upload 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. This is the default method.

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

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

      • OSS: Upload code from an Object Storage Service (OSS) bucket. In this case, you must specify the Bucket Name and Object Name parameters.

      Use Sample Code

      Startup Command

      Note

      This parameter is required if you select Web Function or Container Images.

      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. You can use the bootstrap script to start your program.

      npm run start

      Listener Port

      Note

      This parameter is required if you select Web Function or Container Images.

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

      Execution Timeout Period

      Specify the timeout period for execution of the function. The default 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 for 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 Web Function or Container Images to create the function, you do not need to configure 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

      Function Role

      Specify the RAM role of the function. Function Compute uses this role to generate a temporary key for accessing your Alibaba Cloud resources and pass it to your code. For more information, see Grant Function Compute permissions to access other Alibaba Cloud services.

      mytestrole

      Access to VPC

      Specify whether to allow functions to access virtual private cloud (VPC) resources. For more information, see Configure network settings.

      Yes

      VPC

      This parameter is required if you set Access to VPC to Yes. Create a VPC or select the ID of an existing VPC that you want to access from the drop-down list.

      fc.auto.create.vpc.1632317****

      vSwitch

      This parameter is required if you set Access to VPC to Yes. Create a vSwitch or select the ID of an existing vSwitch from the drop-down list.

      fc.auto.create.vswitch.vpc-bp1p8248****

      Security Group

      This parameter is required if you set Access to VPC to Yes. Create a security group or select an existing security group from the drop-down list.

      fc.auto.create.SecurityGroup.vsw-bp15ftbbbbd****

      Allow Default NIC to Access Internet

      Specify whether to allow functions to access the Internet through the default network interface controller (NIC). If you select No, functions in the current service cannot access the Internet through the default NIC of Function Compute.

      Important

      If you use a static public IP address, you must set Allow Default NIC to Access Internet to No. Otherwise, the configured static public IP address does not take effect. For more information, see Configure static public IP addresses.

      Yes

      Logging

      Specify whether to enable the logging feature. Valid values:

      • Enable: Function Compute sends function execution logs to Simple Log Service for persistent storage. You can debug code, troubleshoot issues, and analyze data based on the logs.

      • Disable: You cannot use Log Service to store or query function execution logs.

      Enable

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

Update a function

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

  2. In the top navigation bar, select a region. On the Functions page, click the function that you want to manage.

  3. On the function details page, click the Configuration tab and modify parameters based on your business requirements. Then, click OK.

    Parameter

    Description

    References

    Basic Configurations

    Configure the basic information about the function. You can modify the Description, Specifications, and Size of Temporary Disk parameters.

    Create a function

    Trigger

    Create a trigger or modify an existing trigger based on your business requirements.

    Manage triggers

    Runtime

    Modify the runtime of the function. You can modify the Runtime, Handler, and Execution Timeout Period parameters.

    Create a function

    Environment Variables

    Configure the environment variables in the runtime of the function.

    Environment variables

    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

    Permissions

    Modify the Function Role and Policy parameters.

    Logs

    Specify whether to enable the logging feature.

    Configure the logging feature

    Network

    Configure the network information for the function.

    Configure network settings

    Storage

    Specify whether to use NAS or OSS.

    Scaling policy

    Configure a scaling policy for on-demand instances or provisioned instances.

    Configure provisioned instances and auto scaling rules

    Asynchronous Mode Configurations

    Configure the retry policy and destination service for asynchronous invocation.

    Overview

    Lifecycle

    Configure lifecycle hooks for the function instance. The Initializer Callback and PreStop Callback parameters are required.

    Function instance lifecycles

    DNS

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

  2. In the top navigation bar, select a region. On the Function page, click the function that you want to manage.

  3. On the function details page, click the Configuration 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 8

Node.js 8

Node.js runtimes

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 3.6

Python 3.6

Python runtimes

Python 3.9

Python 3.9

Python 3.10

Python 3.10

PHP 7.2

PHP 7.2.7

PHP runtimes

Java 11

Java 11

Java runtimes

Java 8

Java 8

.NET Core 3.1

.NET Core 3.1

.NET Core runtimes

Go 1.x

Go 1.8 or later

Go runtimes

Custom Runtime

Custom runtime (Debian 9)

Custom runtimes

Custom runtime (Debian 10)

Custom runtime (Debian 10)

Custom Container

None

Overview

References

  • In addition to the Function Compute console, Function Compute also allows you to use APIs to manage functions. For more information, see Function.