Function Compute application

Updated at:

IoT Edge lets you create edge applications based on Alibaba Cloud Function Compute.

Prerequisites

You have created a function. For more information, see Alibaba Cloud Function Compute.

Procedure

  1. Log on to the IoT Edge console.
  2. In the navigation pane on the left, click Application Management.
  3. On the Application Management page, on the Self-developed Applications tab, click Create Application.
  4. Set the application parameters and click OK.
    • Application information
      ParameterDescription
      Application NameEnter a name for the application. The name can contain letters, digits, and underscores (_). It can be up to 128 characters long.
      Application TypeThe following application types are available:

      Select Function Compute.

      RegionSelect the region where your Function Compute service is located.
      ServiceSelect the service where your function is located.
      FunctionSelect the function that you created.
      Important Functions developed in Python are supported only in Link IoT Edge Pro Edition instances.
      AuthorizationSelect a role to grant permissions to Alibaba Cloud Function Compute. For more information about roles, see Access cloud resources.
      Application VersionSet a version for the application. The version number must be unique within the application.
      Version DescriptionEnter a description for the application version, such as its features. This parameter is optional.
    • Function configuration
      ParameterDescription
      Enable Default Configurations
      • Yes: Use the default system configurations. You do not need to set other parameters for Function configuration and Container configuration.
      • No: Customize the function configuration. You must set other parameters.
      Runtime ModeTwo modes are available: on-demand and persistent.
      • On-demand: This is the native runtime mode of Function Compute. After a function is deployed to an edge, it does not run immediately. The function is loaded and runs only when it is triggered by an event. If no new events trigger the function for a period of time, it stops running. If your program is event-driven and the trigger frequency is less than once every 20 minutes, select this mode. This mode reduces the pressure on the CPU and memory resources of the edge gateway. If events are triggered frequently, the on-demand function remains running to ensure fast responses.
      • Persistent: This is a unique runtime mode for the edge. After a function is deployed to an edge, it is immediately loaded and runs. This mode is suitable for traditional server-side programs that need to run continuously. If your program is a server-side program that needs to listen on a port to respond to requests independently, such as an HTTP Server, select this mode. IoT Edge keeps the function alive. If the function exits unexpectedly, it is restarted.
      Timeout LimitWhen an event is triggered, the handler in the code is invoked to process the event. After the event is processed, an acknowledgement message is sent to return the result and indicate that the processing is complete. If the function does not return a result within the specified timeout period, the function is considered abnormal and is restarted.
      Scheduled RunConfigure the time and frequency at which the function is triggered. The value must be a cron expression. For example, * * * * * indicates that the function is triggered every minute, and 20 * * * * indicates that the function is triggered at the 20th minute of every hour. For more information, see the CRONTAB website.
      Environment VariablesConfigure custom environment variables that can be directly read when the function code runs. Click Add Environment Variable and set a variable name and value to add an environment variable. You can configure up to 10 environment variables.

      This feature separates code from configurations to improve code portability. For example, the function code needs to request services from other hosts on the network. The IP addresses and ports of the servers are usually different in different environments. By passing the IP address and port information as configuration parameters through environment variables, gateways in different environments can share the same function code.

    • Container configuration
      Note If you customize the Container Configuration, you must set Enable Default Configurations to No in the Function Configuration
      ParameterDescription
      Use Host NetworkSpecifies whether to isolate the container's network and use the host network environment directly.
      • Yes: The container's network is not isolated. The host network is used directly.
      • No: The container's network is isolated. You must configure Port Mapping.
      Port MappingThis parameter appears when Use Host Network is set to No. The network environment of the function is completely isolated from the host environment. Through port mapping, you can map the listening port of the function in the container to a port on the host. This allows client programs on different hosts to access the service provided by the function. You can map up to 10 network ports.

      For example, the fc-http-server function runs in a container on the host and provides services on port 80. In this case, client programs on other hosts cannot access the fc-http-server function by accessing port 80 of the host. Therefore, you need to map the container port of the fc-http-server function to a port on the host. For example, map port 80 in the container to port 8080 on the host. This allows client programs on other hosts to access the fc-http-server function in the container by accessing Host IP address:8080.

      Enable Privileged Mode

      The root user in a container is actually a regular user on the host. To perform operations that require root permissions inside the container, such as modifying the system time or using the mount command, you must grant the container privileged mode.

      Note In privileged mode, the container has root permissions on the host. All host devices are mapped to the container by default. You do not need to configure Device Mapping.
      Device MappingThis parameter appears when Enable Privileged Mode is set to No. The device management system is completely isolated from the host environment. When a function needs to access a host device, such as a serial port, you must map the device to the container where the function runs. You can add up to 10 device mappings.
      Volume MappingThe file system is completely isolated from the host environment. When a function needs to access a host file, you must map the file to the container where the function runs. You can add up to 10 volume mappings.
      Memory LimitSet the maximum memory for the container.
      • If the container's memory usage exceeds the limit, the container is restarted.
      • If the memory limit is too small, the application in the container may fail to run.

      The default memory is 1024 MB. Increase the memory limit based on the size of the application in the container.

  5. After you create the application, you can view it on the Self-developed Applications tab of the Application Management page. You can also perform more operations from the Actions
    应用更多操作
    • Version Management

      Click Version Management to add, modify, or delete application versions.

      应用版本管理
    • Delete
      Click Delete to delete the application.
      Note Before you delete an application, you must delete all of its versions. Otherwise, you cannot delete the application.

What to do next

Assign the created edge application to an edge instance. For more information, see Assign an edge application to an edge instance.