The rules engine can forward data to Function Compute, which runs function scripts to process your business data. This topic uses a Thing Specification Language (TSL) communication topic as an example to describe the data forwarding process.
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. For more information, see Feature availability by region.
-
A data source named DataSource is created and a TSL communication topic is added to the data source. For more information, see Add a data source.
-
Create a service and a function in Function Compute. Verify that the function is configured and runs as expected. Function Compute documentation.
Important-
When you create the function, set the Request Handler Type parameter to Handle Event Request.
-
For an Enterprise Edition instance, the Function Compute service and function must be in the same region as the instance.
-
Background
The rules engine forwards device data to Function Compute, where custom function scripts run your business logic.
Usage notes
You can also use the new or previous version of the data forwarding feature to forward data to Function Compute. For more information about the previous version, see Forward data to Function Compute (FC).
Create a data destination
-
Log on to the IoT Platform console.
On the Overview page, find the instance that you want to manage and click the instance ID or instance name.
-
In the left-side navigation pane, choose .
-
On the Data Forwarding page, click Go to New Version in the upper-right corner.
NoteIf you have performed this operation before, you are automatically redirected to the new version of the Data Forwarding page.
- Click the Data Destination tab. On this tab, click Create Data Destination.
-
In the Create Data Destination dialog box, enter a data destination name. In this example, DataPurpose is used. Configure the parameters and click OK.
Parameter
Description
Operation
Select Send data to Function Compute (FC).
Region
Select the region of your Function Compute service.
Service
Select a Function Compute service.
To create a service in the Function Compute console, click Create Service. Manage services.
Function Version
Select a function version:
-
Use Default Version: Invokes the LATEST version of the function.
-
Select Version: Use a specific published version of the service.
To create a version in the Function Compute console, click Create Version. Manage versions.
-
Select Alias: Use a preconfigured alias for a service version.
To create an alias in the Function Compute console, click Create Alias. Manage aliases.
Function
Select the target function.
To create a function in the Function Compute console, click Create Function. Manage functions.
Authorization
Grants IoT Platform permission to write data to Function Compute.
If no RAM role exists, click Create RAM Role to create a RAM role and authorization policy in the RAM console. Create a RAM role.
-
Configure and start a parser
Create a parser named DataParser. For more information, see Step 1: Create a parser.
On the Parser Details page, associate the parser with the created data source.
In the Data Source step of the wizard, click Associate Data Source.
In the dialog box that appears, select DataSource from the Data Source drop-down list, and then click OK.
On the Parser Details page, associate the parser with the created data destination.
Click Data Destination in the wizard. In the Data Destination section, click Associate Data Destination.
In the dialog box that appears, select DataPurpose from the Data Destination drop-down list, and then click OK.
In the Data Destination section, view and save the data destination ID. In this example, the ID is 1000.
When you write the parser script, you must use the data destination ID.
- On the Parser Details page, click Parser.
-
In the code editor, enter a script. For more information about how to modify a script, see Script syntax.
For more information about function parameters, see Function list.
// Use the payload() function to obtain the data that is submitted by devices and convert the data to JSON-formatted data. var data = payload("json"); // Forward submitted TSL data. writeFc(1000, data); -
Click Debugging. In the dialog box that appears, select a product and a device, specify a topic, and then enter payload data to check whether the script runs as expected.
The following figure shows the parameters.

The following result indicates that the script runs as expected.

- Click Publish.
Go to the Parser tab of the Data Forwarding page. Find the DataParser parser and click Start in the Actions column to start the parser.
-
Log on to the Function Compute console. On the details page of the function, click the Logs tab to view the execution records of the function. In the upper-right corner of the details page, choose More > Monitoring to view the monitoring statistics on the function.
ImportantThe monitoring statistics on a function are generated 5 minutes after the function runs.