You can call the CreateDeliveryTask operation to create a delivery task. You can create a delivery task to deliver data from Tablestore to an OSS bucket.
Make sure that you have installed Tablestore SDK for Go that supports delivery service.
Prerequisites
OSS is activated. A bucket is created in the region where a Tablestore instance is deployed. For more information, see Activate OSS.
The Tablestore service linked role (AliyunServiceRoleForOTSDataDelivery) is created in the console. The Alibaba Cloud Resource Name (ARN) of the role is recorded. For more information, see the "Create delivery tasks" section of the Quick start topic.
You can obtain the ARN of the Tablestore service linked role (AliyunServiceRoleForOTSDataDelivery) in the RAM console. Perform the following operations:
On the RAM Roles page, search AliyunServiceRoleForOTSDataDelivery. Then, click the RAM role name. On the role details page, you can view and copy the ARN information of the role.
TableStoreClient is initialized. For more information, see Initialization.
A table is created. Data is written to the table.
Parameters
Parameter | Description |
---|---|
TableName | The name of the table. |
TaskName | The name of the delivery task. The name must be 3 to 16 characters in length and can contain only lowercase letters, digits, and hyphens (-). It must start and end with a lowercase letter or digit. |
TaskConfig | The configurations of the delivery task. Valid values:
|
TaskType | The mode in which to deliver data. Default value: BaseIncTask. Valid values:
|
Examples
func CreateTaskSample(client *tablestore.TableStoreClient) {
createTask := &tablestore.CreateDeliveryTaskRequest{
TableName: "sampleTable",
TaskName: "sampledeliverytask",
TaskType: tablestore.BaseIncTask,
TaskConfig: &tablestore.OSSTaskConfig{
OssPrefix: "sample/year=$yyyy/month=$MM",
OssBucket: "datadeliverytest",
OssEndpoint: "oss-cn-hangzhou.aliyuncs.com",
OssRoleName: "acs:ram::17************45:role/aliyunserviceroleforotsdatadelivery",
Schema: []*tablestore.TaskSchema{
{
ColumnName: "PK1",
OssColumnName: "PK1",
Type: tablestore.ParquetInt64,
},
{
ColumnName: "PK2",
OssColumnName: "PK2",
Type: tablestore.ParquetUtf8,
},
{
ColumnName: "Col1",
OssColumnName: "Col1",
Type: tablestore.ParquetDouble,
},
},
},
}
createResp, err := client.CreateDeliveryTask(createTask)
if err != nil {
log.Fatal("create delivery task failed ", err)
}
fmt.Println("create delivery task success ", createResp.RequestId)
}