After a Tablestore trigger is created, you can write the code of a function. This topic describes how to write a function in the Function Compute console.
Prerequisites
Write function code in Python
Event format
A Tablestore trigger encodes incremental data in CBOR format to form an event in Function Compute. The data format of incremental data is as follows:
{
"Version": "string",
"Records": [
{
"Type": "string",
"Info": {
"Timestamp": int64
},
"PrimaryKey": [
{
"ColumnName": "string",
"Value": formated_value
}
],
"Columns": [
{
"Type": "string",
"ColumnName": "string",
"Value": formated_value,
"Timestamp": int64
}
]
}
]
}
- Version: the version of the payload of the data. The current version is Sync-v1. The value is of type "String."
- Records: an array of incremental data rows in the data table.
- Type: the type of the data row. Valid values: PutRow, UpdateRow, and DeleteRow. The value is of type "String."
- Info: the basic information about the data row.
- Timestamp: the last time when the row was modified. The time must be in UTC. The value is of type "Int64."
- PrimaryKey: an array of primary key columns.
- ColumnName: the name of the primary key column. The value is of type "String."
- Value: the content of the primary key column. The value is of type "formatted_value," which can be Integer, String, or Blob.
- Columns: an array of attribute columns.
- Type: the type of the attribute column. Valid values: Put, DeleteOneVersion, and DeleteAllVersions. The value is of type "String."
- ColumnName: the name of the attribute column. The value is of type "String."
- Value: the content of the attribute column. The value is of type "formatted_value," which can be Integer, Boolean, Double, String, or Blob.
- Timestamp: the last time when the attribute column was modified. The time must be in UTC. The value is of type "Int64."
The sample code of an event is as follows.
{
"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
}
]
}
]
}