Use Function Compute
Function Compute uses an event-driven architecture to automatically process incremental data from Tablestore, enabling real-time responses and automated processing.
How it works
Function Compute uses a Tablestore trigger to automatically process incremental data in Tablestore. When a data table is modified, Tablestore Stream captures these changes in real time. The trigger then monitors the stream and automatically invokes a function to process the new data, enabling immediate and automated responses to data events.
This event-driven approach eliminates the need for polling, ensuring timely data processing and preventing resource waste. Compared to traditional scheduled tasks or manual processing, Function Compute provides superior real-time performance and automation. By using asynchronous processing and elastic scaling, it reduces system complexity and operational overhead, making it ideal for use cases that require immediate 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 suit different business scenarios and technical architectures. For a detailed comparison and guidance on selecting the appropriate type, see Function selection.
Access Tablestore using an event function
Step 1: Enable Tablestore Stream
A Tablestore trigger in Function Compute (FC) relies on Tablestore Stream to capture incremental data. Therefore, you must first enable this feature for the target data table.
Tablestore triggers are available 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 your instance is located, and then click the alias of the target instance.
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 the log expiration time, and then click Enable.
The log expiration time must be a non-zero integer in hours, up to a maximum of 168. This setting cannot be changed once configured. Set this value with caution.
Step 2: Create and configure an event function
When you create a Tablestore trigger, you can only select Tablestore instances and data tables that are in the same region as the function.
Log on to the Function Compute console. In the top navigation bar, select the same region as your Tablestore instance.
In the left-side navigation pane, choose .
Click Create Function, select Event Function as the function type, and then click Create Event Function.
Configure the function parameters as described below. For detailed instructions, see Create an event function.
Function Name: Enter a unique name for the function. The name must be unique within the same account and region and follow the naming conventions.
Runtime: We recommend selecting Built-in Runtime and choose a familiar language and version, such as Python or Java. This topic uses Python 3.12 as an example.
Code Upload Method: Select how to upload your code. This topic uses Upload ZIP as an example. You can download and upload the sample code file: tablestore_trigger_example.zip.
Click Create.
Step 3: Test and validate the event function
Before you configure the Tablestore trigger, test the function by simulating an event. A Tablestore trigger uses the Concise Binary Object Representation (CBOR) format for encoding, but you can use the JSON format to simulate events for debugging.
On the Function Details page, click the arrow next to Test Function and select Configure Test Parameters.
Enter an Event Name, such as
test-event, paste the following sample event into the 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. A successful execution returns
OK. You can view the execution logs on the Log Output tab.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 testing and validating the function, configure the Tablestore trigger to automatically execute the function when the data table changes. Then, verify the trigger by performing a data operation.
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 name for the trigger, such as
test_trigger.Instance: Select the target Tablestore instance.
Table: Select the target data table.
Click OK.
For example, you can insert a row using the Tablestore console.
On the Function Details page, click the Logs tab to view invocation logs and results. In the Actions column, click Request Logs for a specific request to view its detailed logs.
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] --------------------------------------------------
Limitations
For example, a function triggered by an update to Table A should not then update Table A, as this would cause infinite invocations.
If a function execution fails, Function Compute retries the function until the stream data in Tablestore expires.
NoteAn exception during function execution can occur in the following cases:
The function code throws an exception: The function instance has already started, so you are charged for the duration of its execution.
The function fails to start: If the instance fails to start due to an incorrect startup command or other issues, you are not charged.
After you delete a trigger, any running function instances do not stop immediately and will continue to run until they complete or time out.
If a function execution fails, you can disable Tablestore Stream for the data table to prevent infinite retries. Before you disable the feature, ensure that no other triggers are using the data table to avoid disruptions.
FAQ
If you cannot create a Tablestore trigger, verify that the selected region supports this feature.
If you cannot find an existing data table when you create a Tablestore trigger, confirm that the data table and the function are in the same region.
If you repeatedly receive an
Invocation canceled by clienterror when using a Tablestore trigger, this typically means the client-side timeout is shorter than the function's execution time. To resolve this, increase the client-side timeout period. For more information, see What do I do if a client disconnects and reports an 'Invocation canceled by client' error?.If a Tablestore trigger does not run when new data is added to the data table, check the following:
Confirm that Tablestore Stream is enabled for the data table.
Verify that the role configured for the trigger is correct. You can use the default trigger role,
AliyunTableStoreStreamNotificationRole.Check the function logs to see if the execution failed. If a function fails, Function Compute retries it until the stream data in Tablestore expires.