Multiple functions can be created for the same service. These functions share the log resources and role information configured for the service, but are independent and do not affect each other. This topic describes how to create, modify, and delete a function.

Prerequisites

Create a service

Background information

Function Compute allows you to manage a function in the following ways:

Create a function

  1. Log on to the Function Compute console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Services and Functions. On the Services and Functions page, click the service that you require. Then, click Create Function in the upper-right corner.
    create-function
  4. On the Create Function page, move the pointer over the function type or function template that you require and click Configure and Deploy.
    In this example, select Event Function to create an event function.creat_function
  5. On the Create Function page, configure the parameters and click Create.
    config_function

    The following table describes the parameters.

    Parameter Required Description Example
    Function Type Yes The type of the function. Event Function is selected in the example. You cannot modify the type after you select it. Event Function
    Service Name Yes The function is created for the service that you have selected in Step 3 by default. You can also select another existing service from the drop-down list. Service
    Function Name Yes The name of the function. Function
    Runtime Yes Select a language, such as Python, Java, PHP, or Node.js. For more information about the runtime environments supported by Function Compute, see Overview.

    After you select the runtime environment, you can use one of the following methods to upload the function code:

    • Upload Zip File: Select this option and then click Upload Code to upload the function code.
    • Upload Folder: Select this option and then click Select Folder to select the folder to be uploaded.
    • Import from OSS: Select this option and then set Bucket Name and Object Name to upload the function code in OSS.
    • Use Sample Code: Select this option to use the sample code of the Function Compute.
    Note that if you set the runtime environment to Custom Container, you must configure the following additional parameters:
    • Container Image: the URL of the container image.
    • Command: the container startup command.
    • Args: the container startup parameters.
    • Image Acceleration: specifies whether to enable image pull acceleration.
    Node.JS 12.x
    Function Handler Yes The name of the function handler. The value is in the format of [File name].[Function name]. index.handler
    Advanced Settings
    Instance Type Yes The instance category for the function. Valid values:
    • Elastic Instance
    • Performance Instance
    For more information, see Instance specifications and usage modes.
    Elastic Instance
    Memory Yes The memory that is required to execute the function.
    • Select: click the Memory value box and select a value from the drop-down list.
    • Manually enter: click manually enter and customize a memory value. The memory value must be a multiple of 64 MB.
    512 MB
    Timeout Yes The timeout period. The maximum value is 600 seconds. Default value: 60 seconds.
    Note If the execution of the function does not complete before the specified timeout period expires, the function fails to be executed. To set a longer timeout period, you must submit a ticket.
    60
    Single Instance Concurrency No The number of requests that can be concurrently processed by a single instance. For more information, see A single instance that concurrently processes multiple requests.
    Notice This parameter is not valid for the Python language.
    1
    Layer No The name and version of the layer that you want to load. For more information, see Overview. Layer: Node.JS. Version: 2
    Listening Port No The port on which the HTTP server listens for the custom runtime or custom container runtime. 9000
    After the function is created, click the service to which the function belongs on the Services and Functions page to view the created function.create_function_result

Obtain the ARN of a function

  1. Log on to the Function Compute console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Services and Functions. In the Services pane, click the service that you require.
  4. On the Functions tab, find the function whose Alibaba Cloud Resource Name (ARN) you want to obtain and click Copy ARN in the Actions column to copy the function ARN to the clipboard.
    Copy ARN button

Modify a function

  1. Log on to the Function Compute console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Services and Functions. In the Services pane, click the service that you require.
  4. On the Functions tab, find the function that you want to modify and click Modify Configurations in the Actions column.
  5. On the Modify Configurations page, modify the parameters and click Submit.
    Function Compute allows you to modify parameters such as Function Handler, Runtime, Instance Type, Memory, Environment Variables, and Layer.
    Notice The value of the Instance Type parameter can be changed only from Elastic Instance to Performance Instance. If the value of this parameter for your function is Performance Instance, you cannot change it to Elastic Instance.
    Modify a function

Delete a function

Before you delete a service, ensure that you have deleted all triggers from the service. For more information, see Delete a trigger.

  1. Log on to the Function Compute console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Services and Functions. In the Services pane, click the service that you require.
  4. On the Functions tab, find the function that you want to delete and click Delete in the Actions column. In the message that appears, click OK to delete the function.
    Delete a function