Function Compute uses an event-driven mechanism to automatically process incremental data changes from Tablestore. This enables real-time responses and automated processing.
How it works
Function Compute automatically processes incremental data from Tablestore using a Tablestore trigger. When a data table changes, Tablestore Stream captures the incremental changes in real time. The trigger listens for data changes in the stream and automatically invokes the corresponding function for processing. This ensures real-time response and processing of data changes.
This event-driven approach eliminates the need to poll for data changes. It ensures timely processing and avoids wasting resources. Compared to traditional scheduled tasks or manual methods, Function Compute offers better real-time performance and automation. It reduces system complexity and Operations and Maintenance (O&M) costs through asynchronous processing and elastic scaling. This makes it ideal for scenarios that require real-time responses to data changes, such as data synchronization, event notifications, and incremental data archiving.
In addition to event functions, Function Compute also supports other types, such as Web functions and task functions. Different function types are suitable for different business scenarios and technical architecture requirements. For more information about function types and how to select the appropriate one, see Function selection.
Access Tablestore using an event function
Step 1: Enable the Stream feature for a data table
Tablestore triggers in Function Compute (FC) rely on the Stream feature to retrieve incremental data changes from a data table. You must first enable the Stream feature for the target data table.
Tablestore triggers are supported in the following regions: China (Beijing), China (Hangzhou), China (Shanghai), China (Shenzhen), Japan (Tokyo), Singapore, Germany (Frankfurt), and China (Hong Kong).
Log on to the Tablestore console. In the top navigation bar, select the region where the instance is located, and then click the target instance alias.
On the Instance Details page, click the name of the target data table in the Tables list.
Click the Tunnels tab, and then click Enable to the right of Stream Information.
In the Enable Stream dialog box, set Log Expiration Time, and then click Enable.
The Log Expiration Time must be a non-zero integer in hours. The maximum value is 168 hours. The log expiration duration cannot be modified after it is set. Set this value with caution.
Step 2: Create and configure an event function
When you create a Tablestore trigger, you can select only Tablestore instances and data tables that are in the same region as the current function. Ensure that the function and the target data table are in the same region.
Log on to the Function Compute console. In the top navigation bar, select the same region as your Tablestore instance.
In the navigation pane on the left, click .
Click Create Function, select Event Function, and then click Create Event Function.
Configure the function parameters as follows. For detailed configuration instructions, see Create an event function.
Function Name: The name of the function. The name must be unique within the same account and region and must comply with the naming conventions.
Runtime: We recommend that you select Built-in Runtime and a familiar language and version, such as Python and Java. This example uses Python 3.12.
Code Upload Method: Select the method to upload code to Function Compute. In this example, select Upload ZIP. You can download and upload the sample code tablestore_trigger_example.zip.
Click Create to create the function.
Step 3: Test and validate the event function
Before you configure the Tablestore trigger, test the function by simulating an event. Tablestore triggers use the CBOR format for encoding. For testing, you can simulate this with the JSON format.
On the Function Details page, click the drop-down arrow next to Test Function, and then click Configure Test Parameters.
Enter an Event Name, such as
test-event, enter the following sample event in the text editor, and then click OK.{ "Version": "Sync-v1", "Records": [ { "Type": "PutRow", "Info": { "Timestamp": 1506416585740836 }, "PrimaryKey": [ { "ColumnName": "pk_0", "Value": 1506416585881590900 }, { "ColumnName": "pk_1", "Value": "2017-09-26 17:03:05.8815909 +0800 CST" }, { "ColumnName": "pk_2", "Value": 1506416585741000 } ], "Columns": [ { "Type": "Put", "ColumnName": "attr_0", "Value": "hello_table_store", "Timestamp": 1506416585741 }, { "Type": "Put", "ColumnName": "attr_1", "Value": 1506416585881590900, "Timestamp": 1506416585741 } ] } ] }Click Test Function and wait for the test to complete. If the execution is successful,
OKis returned. Click Log Output to view the execution log.2025-11-24 16:02:59 1-69241131-15e0c7d6-8ec1eb81c700 [INFO] Begin to handle event 2025-11-24 16:02:59 1-69241131-15e0c7d6-8ec1eb81c700 [INFO] -------------------------------------------------- 2025-11-24 16:02:59 1-69241131-15e0c7d6-8ec1eb81c700 [INFO] Event Type: PutRow 2025-11-24 16:02:59 1-69241131-15e0c7d6-8ec1eb81c700 [INFO] Timestamp: 1506416585740836 2025-11-24 16:02:59 1-69241131-15e0c7d6-8ec1eb81c700 [INFO] Primary Keys: 2025-11-24 16:02:59 1-69241131-15e0c7d6-8ec1eb81c700 [INFO] Name: pk_0, Value: 1506416585881590900 2025-11-24 16:02:59 1-69241131-15e0c7d6-8ec1eb81c700 [INFO] Name: pk_1, Value: 2017-09-26 17:03:05.8815909 +0800 CST 2025-11-24 16:02:59 1-69241131-15e0c7d6-8ec1eb81c700 [INFO] Name: pk_2, Value: 1506416585741000 2025-11-24 16:02:59 1-69241131-15e0c7d6-8ec1eb81c700 [INFO] Attribute Columns: 2025-11-24 16:02:59 1-69241131-15e0c7d6-8ec1eb81c700 [INFO] Type: Put, Name: attr_0, Value: hello_table_store, Timestamp: 1506416585741 2025-11-24 16:02:59 1-69241131-15e0c7d6-8ec1eb81c700 [INFO] Type: Put, Name: attr_1, Value: 1506416585881590900, Timestamp: 1506416585741 2025-11-24 16:02:59 1-69241131-15e0c7d6-8ec1eb81c700 [INFO] --------------------------------------------------
Step 4: Configure and validate the trigger
After you test and validate the function, configure a Tablestore trigger to automatically respond to data table changes. Then, verify the trigger's functionality by performing data operations.
On the Function Details page, click the Triggers tab, and then click Create Trigger.
Configure the trigger parameters as follows.
Trigger Type: Select Tablestore.
Name: Enter a custom trigger name, such as
test_trigger.Instance: Select the target Tablestore instance.
Table: Select the target data table.
Click OK to create the trigger.
Insert or update a row of data in the Tablestore data table. This example shows how to insert a row in the Tablestore console.
On the Function Details page, click the Logs tab to view function invocation logs and results. In the Actions column, click Request Logs to view detailed log information.
2025-11-24 16:30:12 1-69241793-15071122-c8e16b8b5ce5 [INFO] Begin to handle event 2025-11-24 16:30:12 1-69241793-15071122-c8e16b8b5ce5 [INFO] -------------------------------------------------- 2025-11-24 16:30:12 1-69241793-15071122-c8e16b8b5ce5 [INFO] Event Type: PutRow 2025-11-24 16:30:12 1-69241793-15071122-c8e16b8b5ce5 [INFO] Timestamp: 1763973009228992 2025-11-24 16:30:12 1-69241793-15071122-c8e16b8b5ce5 [INFO] Primary Keys: 2025-11-24 16:30:12 1-69241793-15071122-c8e16b8b5ce5 [INFO] Name: id, Value: 8 2025-11-24 16:30:12 1-69241793-15071122-c8e16b8b5ce5 [INFO] Name: name, Value: test-name 2025-11-24 16:30:12 1-69241793-15071122-c8e16b8b5ce5 [INFO] Attribute Columns: 2025-11-24 16:30:12 1-69241793-15071122-c8e16b8b5ce5 [INFO] Type: Put, Name: age, Value: 18, Timestamp: 1763973009229 2025-11-24 16:30:12 1-69241793-15071122-c8e16b8b5ce5 [INFO] --------------------------------------------------
Quotas and limits
When you write function code, do not create a logic loop. For example, do not configure a trigger for Table A to invoke a function that updates data in Table A. This causes infinite function invocations.
If an exception occurs during function execution, the function is retried indefinitely until the log data in Tablestore expires.
NoteA function execution exception can occur in the following situations:
The function code throws an exception: The function instance has started, and you are charged for its running time.
The function fails to start: The function instance does not start because of an incorrect startup command or other reasons. You are not charged in this case.
If a function execution exception occurs, disable the Stream feature for the data table to prevent infinite retries. Before you disable the Stream feature, make sure that no other triggers are using the data table to avoid affecting other triggers.
FAQ
If you cannot create a Tablestore trigger in a specific region, check the list of supported regions.
If you cannot find your Tablestore data table when creating a Tablestore trigger, confirm that the Tablestore data table and the Function Compute service are in the same region.
If an error indicating that the client canceled the request is repeatedly reported when you use a Tablestore trigger, this usually happens because the timeout period set on the client is shorter than the function's running time. We recommend that you increase the client's timeout period. For more information, see What do I do if a client disconnects and an "Invocation canceled by client" error is reported?.
If new data is added to a Tablestore data table but the Tablestore trigger is not invoked, troubleshoot the issue by checking the following items:
Check whether the Stream feature is enabled for the data table.
Check whether the role configured for the trigger is correct. You can use the default trigger role
AliyunTableStoreStreamNotificationRole.Check the function execution logs to determine if the function failed to run. If a function fails, it is retried until the log data in Tablestore expires.