You can use the data forwarding feature of the rules engine to forward data to Function Compute. Then, Function Compute runs function scripts to process data.

Prerequisites

  • An IoT Platform instance whose data can be forwarded to Function Compute is created in a region that supports data forwarding to Function Compute.
    Supported instance Supported region
    Enterprise Edition instances: Standard and Video
    • China (Shanghai)
    • Japan (Tokyo)
    Public instances
    • China (Shanghai)
    • Singapore
    • Japan (Tokyo)
  • A Function Compute service and a function are created. The function is configured and can run as expected after verification. For more information, see the Function Compute documentation.
    Important
    • When you create the function, you can set the Function Type parameter only to Event Function.
    • If you use an IoT Platform Enterprise Edition instance, Function Compute must be activated in the same region where the Enterprise Edition instance resides.
  • A data forwarding rule is created and an SQL statement that is used to process data is written. For more information, see Configure a data forwarding rule.

Background information

The rules engine uses the data forwarding feature to forward device data to Function Compute. Then, Function Compute runs business-specific function scripts to implement various business features.

The following figure shows the data forwarding process.

Forward data to Function Compute

Usage notes

You can use the new version or old version of the data forwarding feature to forward data to Function Compute. For more information about how to use the new version of the data forwarding feature, see Use the new version of the data forwarding feature to forward data to Function Compute.

Procedure

  1. Log on to the IoT Platform console.
  2. On the Overview page, find the instance that you want to manage and click the instance name to go to the Instance Details page.
    Important Enterprise Edition instances are available in the China (Shanghai) and Japan (Tokyo) regions. If the Enterprise Edition instances are unavailable in the region that you select, skip this step.
    Overview
  3. In the left-side navigation pane, choose Rules Engine > Data Forwarding.
  4. Click View next to the rule that you want to manage. The Data Forwarding Rule page appears.
    Important If the new version of the Data Forwarding page is displayed, click Back to Previous Version in the upper-right corner, and then click View in the Actions column of the rule that you want to manage.
  5. In the Forward Data section, click Add Operation.
  6. In the Add Operation dialog box, select Send Data to Function Compute from the Operation drop-down list. Configure other parameters as prompted and click OK. The following table describes the parameters.
    Parameter Description
    Operation Select Send Data to Function Compute.
    Region Select the region where your Function Compute service is deployed.
    Service Select a Function Compute service.

    You can click Create Service to go to the Function Compute console and create a service. For more information, see Manage services.

    Function Version The scope of the update. Valid values:
    • Use Default Version: Use the default version of the Function Compute service. The default version is LATEST.
    • Select Version: Select the service version that you published.

      You can click Create Version to go to the Function Compute console and create a version. For more information, see Manage versions.

    • Select Alias: Select the alias that you specified for the version of the Function Compute service.

      You can click Create Alias to go to the Function Compute console and create an alias. For more information, see Manage aliases.

    Function Select the function that you want to use to receive data.

    You can click Create Function to go to the Function Compute console and create a function. For more information, see Manage functions.

    Grant permissions Grant IoT Platform the permissions to write data to Function Compute.

    If no RAM roles exist, click Create RAM Role to go to the Resource Access Management (RAM) console, create a RAM role, and then grant permissions to the RAM role. For more information, see Create a RAM role.

  7. Go to the Data Forwarding page, find the rule that you managed, and then click Start in the Actions column of the rule.
  8. Perform a test.
    1. Send messages to the destination topic based on the topic category that is defined in the SQL statement of the data forwarding rule. For information about how to use topics, see Topics. For more information about how to debug upstream or downstream messaging between devices and IoT Platform, see Device simulation.
    2. Log on to the Function Compute console. On the details page of the function, the Logs tab displays the execution logs of the function. In the upper-right corner of the details page, click Monitoring Dashboard to view the monitoring statistics of the function.
      Important The monitoring statistics of a function are generated 5 minutes after the function is executed.

Example

Push device data to DingTalk groups