This topic introduces how to use Function Compute to create edge applications.

Prerequisites

A function is created. For more information, see Function Compute.

Procedure

  1. Log on to the IoT Platform console. In the left-side navigation pane, choose Link IoT Edge > Applications.
  2. On the Applications page, click Create Application.
    Create an application
  3. On the page that appears, specify the parameters as prompted and click Confirm.
    • Application InformationFunction Compute (application information)
      Table 1. Parameters
      Parameter Description
      Application Name The name of the edge application. The application name must be 1 to 128 characters in length, and can contain letters, digits, and underscores (_).
      Application Type The method that is used to create the edge application. The valid values are described as follows:
      • Function Compute: This value indicates that the edge application is created by using Function Compute.
      • Container Image: This value indicates that the edge application is created by using Container Registry.
      • Local Upload: This value indicates that the edge application is created by using locally developed functions.

      In this example, select Function Compute.

      Region The region where your Function Compute service resides.
      Service The service where the function resides.
      Function The function that you have created.
      Notice You can use functions that are created by using the Python programming language only in Link IoT Edge Pro Edition.
      Authorization The RAM role that is assumed by Link IoT Edge to access Function Compute. For more information, see Access resources of other Alibaba Cloud services.
      Application Version The version number of the edge application. You cannot specify two identical version numbers for an edge application.
      Version Description The description of the edge application version. For example, you can specify the version features. This parameter is optional.
    • Function ConfigurationsFunction Compute (function configurations)
      Table 2. Parameters
      Parameter Description
      Running Mode The running mode of the function. The valid values are described as follows:
      • On-demand: This running mode is native to Function Compute. After functions are deployed to the edge, the functions are triggered by events. If no event triggers are identified during a specified period, running functions stop being applied. We recommend that you select this running mode if your program is triggered by events every less than 20 minutes. This reduces the consumed resources of edge gateways, such as CPU and memory. If your program is frequently triggered by events, functions can be run on demand to reduce the event response time.
      • Continuous: This running mode is only available at the edge. Functions are loaded and run instantly after the functions are deployed to the edge. This helps you meet the needs of server programs that are required to run on a permanent basis. We recommend that you select this running mode if you are using server programs and the listening ports must respond to requests. One of the examples is HTTP servers. Link IoT Edge ensures that functions run on a permanent basis. Functions are automatically resumed if they stop working due to unexpected errors.
      Memory Limit The upper limit for the memory of the function. If the consumed memory resource of a function reaches the upper limit, the function is restarted. This allows you to prevent system instability that is caused by memory leaks. If the upper limit is set to an excessively small value, the function may fail to run. The default upper limit is 512 MB. You can keep the default setting.
      Timeout Limit The time-out period. If a specified event is identified, the edge application that is created based on Function Compute calls the handler function in the code to process the event. After the event is processed, the handler function sends response messages and returns the processing result. If the handler function does not return the processing result before the specified time-out period expires, the handler function fails to run as expected. In this scenario, the handler function is restarted.
      Scheduled Execution Specifies whether to configure scheduled running for the function. If you enable this option, you can configure when and how often the function is triggered by using a CRON expression. For example, * * * * * indicates that the function is triggered every minute, and 20 * * * * indicates that the function is triggered at the twentieth minute of each hour. For more information, see CRONAB.
      Environment Variables The custom environment variables. The edge application that is created based on Function Compute can read the specified environment variables when you run the function code. To add an environment variable, click Add Environment Variable. Then, specify the variable name and variable value. You can add a maximum of 10 environment variables.

      Environment variables allow you to enhance code portability by separating configurations from code. For example, to run the function code, you may need to send requests to call services from other servers in the network. In most cases, the server IP address and port number vary based on the network environment. In this scenario, you can specify the IP address and port number as input parameters by using environment variables. This ensures that the Function Compute code is portable across gateways in various network environments.

    • Container ConfigurationsFunction Compute (container configurations)
      Table 3. Parameters
      Parameter Description
      Host Mode Specifies whether to isolate the container network from the host network. The valid values are described as follows:
      • Yes: This value indicates that the container network is the same as the host network.
      • No: This value indicates that the container network is isolated from the host network. If you select this option, you must configure the Network Port Mapping settings.
      Network Port Mapping The mappings between host network ports and container network ports. This parameter is available only when Host Mode is set to No. The network where the function runs is isolated from the host network. You can map the listening port of the function in the container to a host network port. This allows client programs on various hosts to access the services that are provided by the function. You can specify a maximum of 10 entries.

      For example, the fc-http-server function runs in a host container, and provides services by using socket port 80. The client programs on other hosts cannot access the fc-http-server function by accessing port 80 on the current host. To enable the client programs on other hosts to access the fc-http-server function, you must map the network port (port 80) in the container where the function runs to a host network port, such as port 8080. Then, the client programs on other hosts can access the IP address:port 8080 in the host network, and use the services provided by the fc-http-server function.

      Privilege Mode

      Specifies whether to enable the privilege mode. Root users of containers can access host services only as general users. If you want to change the system time or run the mount command in containers, you must be granted the required root permissions. In this scenario, you must enable the privilege mode for the containers.

      Note If you enable the privilege mode, applications and programs in the containers are granted the host root permissions, and all the host devices are mapped to the containers. Therefore, you do not need to configure the Device Mapping settings.
      Device Mapping The device mappings. This parameter is available only when you select No for Privilege Mode. The network where the device management system resides is isolated from the host network. To enable a function to access a host device such as a serial interface, you must map the device to the container where the function runs. You can specify a maximum of 10 entries.
      Volume Mapping The volume mappings. The network where the file system resides is isolated from the host network. To enable a function to access a host file, you must map the file to the container where the function runs. You can specify a maximum of 10 entries.
  4. View the edge application that you have created. You can choose Link IoT Edge > Applications, and view the edge application on the Applications page. You can also manage the edge application by clicking the options in the Actions column.
    Manage the edge application
    • Manage versions

      To manage versions, click Version Management. On the page that appears, you can create, modify, or delete versions based on your business requirements.

      Version management
    • Delete the edge application

      To delete the edge application, click Delete. If you delete the edge application, all versions of the edge application are deleted. Proceed with caution.

What to do next

You can assign the edge application that has been created to the edge instance. For more information, see Assign edge applications to edge instances. You can also create custom edge applications by using Function Compute socket on the instructions provided in the Examples of Function Compute-based edge applications.