Function Overview

Last updated: 2022-01-04 16:23:04

    A function is the basic unit of management and operation in SCF, which usually consists of a series of configuration items and executable code/packages. You can trigger a function through APIs. You can also pass different events to a function through different triggers to trigger it for event processing.

    Relevant Concepts of Function

    • Region: a function resource must belong to a certain region. For regions supported by SCF, please see Billing Overview.
    • Namespace: a function resource must be created under a certain namespace in a certain region. Each region has a default namespace. You can also create namespaces, whose names cannot be modified after creation.
    • Function name: it is the unique identifier of a function, must be unique under the same namespace, and cannot be modified after creation.
    • Function type: SCF supports two function types: event-triggered function and HTTP-triggered function.
      • Event-Triggered functions are triggered by events in a specified format, such as scheduled triggering events and COS triggering events. For more information on the event structure, please see Trigger Overview.
      • HTTP-Triggered functions focus on optimizing web services and can directly accept and process HTTP requests. For more information, please see Function Overview.
    • Runtime environment: execution environment of the function code. Currently, SCF supports Python, Node.js, PHP, Java, Go, Custom Runtime, and image deployment.
    • Function execution method: it specifies the starting file and function while invoking the function. There are three ways as follows:
      • For Go programming, use the "[FileName]" format, such as main.
      • For Python, Node.js, or PHP programming, use the "[FileName].[FunctionName]" format, such as index.main_handler.
        Note

        Please note that FileName does not include the file name extension, and FunctionName is the name of the entry function. Make sure that the file name extension matches the programming language. For example, for Python programming, the file name extension is .py, and for Node.js programming, the file name extension is .js.

      • For Java programming, use the "[package].[class]::[method]" format, such as example.Hello::mainHandler.
    • Function description: used to record information such as the purpose of the function, which is optional.

    Relevant Configurations of Function

    In addition to the above configuration items, you can also modify the following configuration items for function execution by editing the function configuration in the console or updating function configuration:

    • Memory size: amount of memory available for the function during execution, which ranges from 64 MB to 120 GB in increments of 128 MB and is 128 MB by default. When the memory is greater than or equal to 6 GB, you should submit an application for large resources.

    • CPU computing power: CPU processing power of the function, which is directly proportional to the function memory. You can increase the memory to get more CPU computing power. 1,280 MB memory and 3,072 MB memory correspond to 1 and 2 cores of computing power, respectively. When the memory is greater than or equal to 6 GB, the computing power will be further released as shown below:

      Execution memory (GB) CPU computing power (core)
      6 4
      14 8
      30 16
      60 32
      128 64
    • Initialization timeout period: maximum initialization duration of the function between 3 and 300 seconds (90 seconds for image deployment-based functions and 60 seconds for other functions by default).

      Note
      • The function initialization phase includes the preparations of function code, image, layer, and other relevant resources and execution of the main process code of the function. If your function has a larger image or complex business logic, please increase the initialization timeout period appropriately.
      • The initialization timeout period only takes effect in the scenario where the trigger container is cold started for invocation.
      • The client waiting time is better to be slightly larger than the sum of the initialization timeout period and the execution timeout period.
    • Execution timeout period: maximum execution duration of the function between 1 and 900 seconds (3 seconds by default).

    • Environment variable: it can be defined in the configuration and obtained from the environment when the function is executed.

    • Execution role: it grants the corresponding permissions of the policy contained in it to the function. For more information, please see Role and Authorization. For example, to execute the action of writing an object into COS in the function code, you should configure an execution role with the permission to write COS.

    • Log configuration: it delivers function invocation logs to the specified log topic. For more information, please see Log Search Guide.

    • Network configuration: it configures the function network access permissions. For more information, please see Network Configuration Management.

      • Public network: it is enabled by default. The function cannot access public network resources after it is disabled.
      • Fixed outbound IP: after it is enabled, the platform will assign a fixed public network outbound IP to the function.
      • VPC: after it is enabled, the function can access resources in the same VPC.
    • File system: after it is enabled, the function can access resources of the mounted file system.

    • Execution configuration:

      • Async execution: after it is enabled, the function execution timeout period can be up to 24 hours. It cannot be modified after function creation.
      • Linkage trace: it can be enabled only for async execution. When it's enabled, it will keep the logs of real-time status of response for async function events. You can query and stop the event and check the related statistics. Data of event status will be retained for three days.
    • Async invocation configuration: you can use this configuration item to set the retry policy for async invocation. You can also configure the dead letter queue to collect error event information and analyze the failure cause.

    Executable Operations for Function

    • Creating function: creates a function.
    • Updating function:
      • Updating function configuration: updates the configuration items of the function.
      • Updating function code: updates the execution code of the function.
    • Getting details: gets function configuration, trigger, and code details.
    • Testing function: triggers the function in a sync or async manner as needed.
    • Getting log: gets the log of function execution and output.
    • Deleting function: deletes a function that is no longer needed.

    Function trigger-related operations include: