TableStoreClient is a client for Tablestore. TableStoreClient provides various methods that you can use to manage tables and perform read and write operations on a single row or multiple rows. Before you can use the TimeSeries model, you must initialize the TimeseriesClient.

Obtain an endpoint

An endpoint is a domain name that is used to access a Tablestore instance in a region. To query an endpoint, perform the following steps:

  1. Log on to the Tablestore console.
  2. Click the name of the instance to go to the Instance Details tab.
    On the Instance Details tab, you can view the endpoints of the instance in the Instance Access URL section.
Note For more information about endpoints, see Endpoint.

Configure an AccessKey pair

Before you can connect to Tablestore, you must have an AccessKey pair that consists of an AccessKey ID and an AccessKey secret. The AccessKey pair is used to verify your identity. Tablestore supports the following types of AccessKey pairs:

  • The AccessKey pair of an Alibaba Cloud account. To obtain the AccessKey pair of an Alibaba Cloud account, perform the following steps:
    1. On the Alibaba Cloud official website, register an Alibaba Cloud account.
    2. Create an AccessKey pair in the RAM console.
  • The AccessKey pair of a RAM user that is authorized to access Tablestore. To obtain the AccessKey pair of a RAM user, perform the following steps:
    1. Log on to the RAM console by using an Alibaba Cloud account. Then, create a RAM user or find an existing RAM user.
    2. Grant the RAM user the permissions to access Tablestore.
    3. After the RAM user is granted the permissions to access Tablestore, you can use the AccessKey pair of the RAM user to access Tablestore.
  • Temporary access credentials that are obtained from Security Token Service (STS). The following process shows how temporary access credentials are obtained from STS:
    1. The application server uses RAM or STS to obtain access credentials that consist of a temporary AccessKey ID, an AccessKey secret, and a token, and then sends the access credentials to you.
    2. You can use the access credentials to access Tablestore.

Initialize the TableStoreClient

After you obtain the AccessKey ID and AccessKey secret, you can initialize the TableStoreClient. The following sample code shows how to initialize the TableStoreClient.

  • Operation
    // Initialize a TableStoreClient instance. 
    // endPoint specifies the endpoint that is used to access the Tablestore instance. The endpoint must start with https:// or http://. Example: https://instance.cn-hangzhou.ots.aliyun.com:80. 
    // accessKeyId specifies the AccessKey ID that is used to access the Tablestore instance. To obtain an AccessKey ID, you can visit the official website of Alibaba Cloud or contact an administrator. 
    // accessKeySecret specifies the AccessKey secret that is used to access the Tablestore instance. To obtain an AccessKey secret, you can visit the official website of Alibaba Cloud or contact an administrator. 
    // instanceName specifies the name of the instance that you want to access. You can create an instance in the Tablestore console or contact an administrator to obtain the name of an existing instance. 
    func NewClient(endPoint, instanceName, accessKeyId, accessKeySecret string, options ...ClientOption) *TableStoreClient                   
  • Example
    client = tablestore.NewClient("your_instance_endpoint",  "your_instance_name", "your_user_id", "your_user_key")          

Initialize the TimeseriesClient

After you obtain the AccessKey ID and AccessKey secret, you can initialize the TimeseriesClient. The following sample code shows how to initialize the TimeseriesClient.

  • Operation
    // Initialize a TimeseriesClient instance. 
    // endPoint specifies the endpoint that is used to access the Tablestore instance. The instance must start with https:// or http://. Example: https://instance.cn-hangzhou.ots.aliyun.com:80. 
    // accessKeyId specifies the AccessKey ID that is used to access the Tablestore instance. To obtain an AccessKey ID, you can visit the official website of Alibaba Cloud or contact an administrator. 
    // accessKeySecret specifies the AccessKey secret that is used to access the Tablestore instance. To obtain an AccessKey secret, you can visit the official website of Alibaba Cloud or contact an administrator. 
    // instanceName specifies the name of the instance that you want to access. You can create an instance in the Tablestore console or contact an administrator to obtain the name of an existing instance. 
    func NewTimeseriesClient(endPoint, instanceName, accessKeyId, accessKeySecret string , options ...TimeseriesClientOption) *TimeseriesClient
  • Example
    timeseriesClient = tablestore.NewTimeseriesClient("your_instance_endpoint",  "your_instance_name", "your_user_ak_id", "your_user_ak_key")