All Products
Search
Document Center

Tablestore:Initialize a Tablestore client

Last Updated:Feb 25, 2025

A Tablestore client is a client for Tablestore. A Tablestore client provides various methods that you can use to manage tables and perform read and write operations on a single row or multiple rows. To use Tablestore SDK for Node.js to initiate a request, you must initialize a Tablestore client instance and modify the default configurations of ClientConfig based on your business requirements.

Preparations

Before you initialize a Tablestore client, you must obtain an endpoint of the Tablestore instance that you want to access, install Tablestore SDK for Node.js, and configure access credentials.

Obtain an endpoint of the Tablestore instance

After you create a Tablestore instance, you must obtain an endpoint of the instance. Then, you can use the endpoint to access the instance.

An endpoint is a domain name that is used to access a Tablestore instance in a region. For example, https://sun.cn-hangzhou.ots.aliyuncs.com is the public endpoint that is used to access the instance named sun in the China (Hangzhou) region based on the Internet over HTTPS. For more information, see Endpoints.

Important

You can access Tablestore by using public and internal endpoints.

  1. Activate Tablestore and create an instance. For more information, see Activate Tablestore and create an instance.

  2. Obtain an endpoint of the created instance.

    1. Log on to the Tablestore console.

    2. On the Overview page, find the instance that you created and click the name of the instance.

    3. In the Instance Access URL section of the Instance Details tab, view the endpoints of the instance.

      image

Install Tablestore SDK for Node.js

For more information, see Install Tablestore SDK for Node.js.

Configure access credentials

To access Tablestore, you must have a valid AccessKey pair to verify your identity. For more information, see Configure access credentials.

Initialize a Tablestore client

To use Tablestore SDK for Node.js, you must first create a Tablestore client. Then, you can call the operations of the client to access Tablestore.

Examples

Important

The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. We recommend that you do not hard-code the AccessKey ID and AccessKey secret into your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. In the examples, the security token and AccessKey pair are saved to environment variables.

Use an AccessKey pair

Note

Before you run the sample code, make sure that the OTS_AK_ENV and OTS_SK_ENV environment variables are configured. For more information, see Configure access credentials.

var accessKeyId = process.env.OTS_AK_ENV;
var secretAccessKey = process.env.OTS_SK_ENV;
var endpoint = 'yourEndpoint';
var instancename = 'yourInstance';

var client = new TableStore.Client({
    accessKeyId: accessKeyId,
    secretAccessKey: secretAccessKey,
    endpoint: endpoint,
    instancename: instancename,
    maxRetries:20,// The maximum number of retries. Default value: 20. You can leave this parameter empty. 
});

The following table describes the parameters.

Parameter

Example

Description

endpoint

https://myinstance.cn-hangzhou.ots.aliyuncs.com

The endpoint that is used to access the Tablestore instance. For more information, see Obtain an endpoint of the Tablestore instance.

accessKeyId

process.env.OTS_AK_ENV

The AccessKey pair that is obtained from environment variables. Make sure that the environment variables are configured.

secretAccessKey

process.env.OTS_SK_ENV

instancename

myinstance

The name of the Tablestore instance that you want to access. For more information, see Instances.

maxRetries

20

The maximum number of retries allowed when an error occurs.

Use Security Token Service

Note

Before you run the sample code, make sure that the OTS_AK_ENV, OTS_SK_ENV, and OTS_SESSION_TOKEN environment variables are configured. For more information, see Configure access credentials.

var accessKeyId = process.env.OTS_AK_ENV;
var secretAccessKey = process.env.OTS_SK_ENV;
var stsToken = process.env.OTS_SESSION_TOKEN;
var endpoint = 'yourEndpoint';
var instancename = 'yourInstance';

var client = new TableStore.Client({
    accessKeyId: accessKeyId,
    secretAccessKey: secretAccessKey,
    stsToken: stsToken,
    endpoint: endpoint,
    instancename: instancename,
});

The following table describes the parameters.

Parameter

Example

Description

endpoint

https://myinstance.cn-hangzhou.ots.aliyuncs.com

The endpoint that is used to access the Tablestore instance. For more information, see Obtain an endpoint of the Tablestore instance.

accessKeyId

process.env.OTS_AK_ENV

The AccessKey pair and security token that are obtained from environment variables. Make sure that the environment variables are configured.

accessKeySecret

process.env.OTS_SK_ENV

stsToken

process.env.OTS_SESSION_TOKEN

instancename

myinstance

The name of the Tablestore instance that you want to access. For more information, see Instances.

FAQ