Resource Access Management (RAM) helps you manage user identities and resource access permissions. For enhanced security, using a RAM user's AccessKey pair to access Tablestore resources is more secure than using your Alibaba Cloud account credentials. This topic describes how to use a RAM user's AccessKey pair to access Tablestore resources.
Background
A RAM user is an identity type in Resource Access Management (RAM). You can create RAM users under your Alibaba Cloud account and grant them specific permissions. This allows different RAM users to have different levels of access to your resources.
Procedure
To access Tablestore with a RAM user's AccessKey pair, create a RAM user, grant the user permissions to access Tablestore, and then use the user's Tablestore to access Tablestore resources.
Step 1: Create a RAM user
Log on to the RAM console by using your Alibaba Cloud account or a RAM user that has administrative permissions.
In the navigation pane on the left, choose Identities > Users.
On the Users page, click Create User.
On the Create User page, in the User Account Information section, configure the user's basic information:
Logon Name: The logon name can contain letters, digits, periods (.), hyphens (-), and underscores (_). It can be up to 64 characters in length.
Display Name: The display name can be up to 128 characters in length.
Tag: Click the
icon and enter a tag key and a tag value. Adding a tag helps you find and manage the RAM user.
NoteYou can click Add User to create multiple RAM users in a batch.
In the Access Mode section, select Programmatic Access, and then click OK.
NoteTo allow the RAM user to log on to the Alibaba Cloud Management Console, select Console Access.
In the Actions column, click Copy to save the RAM user information. You can also copy the AccessKey ID and AccessKey secret individually.
ImportantThe AccessKey secret is shown only once upon creation and cannot be retrieved later. Store it in a secure location immediately.
Step 2: Grant RAM user permissions for Tablestore
After you create a RAM user, you must grant the user permissions to access Tablestore.
Default policy
This example shows how to grant a RAM user permissions to access Tablestore by attaching the AliyunOTSFullAccess policy.
The AliyunOTSFullAccess policy grants full access to Tablestore. You can also grant permissions by using other default policies:
For read-only access, grant the RAM user the
AliyunOTSReadOnlyAccesspolicy.For write-only access, grant the RAM user the
AliyunOTSWriteOnlyAccesspolicy.
In the navigation pane on the left, choose Identities > Users.
On the Users page, find the target RAM user.
Click Add Permissions in the Actions column for the RAM user.
In the Grant Permission panel, in the Policy section, search for and select
AliyunOTSFullAccess.Click Grant Permissions.
Custom policy
Create a custom policy.
In the navigation pane on the left, choose Permissions > Policies.
On the Policies page, click Create Policy.
On the Create Policy page, click the JSON tab, enter your policy script in the editor, and then click OK.
NoteThe following example script grants a RAM user permission to access a single instance. You can customize the policy to control access at the table or API operation level, or based on conditions such as IP address or time of access. For more information about RAM policies, see Custom RAM policy.
{ "Version": "1", "Statement": [ { "Effect": "Allow", "Action": "ots:*", "Resource": "acs:ots:*:*:instance/your_instance_name*" } ] }In the Create Policy dialog box, enter a policy name, such as
TestRAMPolicy, and then click OK.
Attach the custom policy to the RAM user.
In the navigation pane on the left, choose Identities > Users.
On the Users page, find the target RAM user.
Click Add Permissions in the Actions column for the RAM user.
In the Grant Permission panel, in the Policy section, search for and select the custom policy that you created.
Click Grant Permissions.
On the Users page, you can click a username to go to the user details page. On the Permissions tab, you can view the policies that are granted to the user.
Step 3: Use the AccessKey pair to access Tablestore
Before you begin
Create an instance and a data table in the Tablestore console.
Obtain the instance name, endpoint, and region ID.
ImportantBy default, public network access is disabled for newly created instances. If you need to access resources in an instance over the internet, you must enable public network access for the instance.
Configure environment variables. After configuration is complete, restart or refresh your compilation and runtime environment, including IDE, command-line interface, other desktop applications, and background services to ensure that the latest system environment variables are successfully loaded.
Linux
Run the following commands in the command-line interface to append environment variable settings to the
~/.bashrcfile.echo "export TABLESTORE_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.bashrc echo "export TABLESTORE_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.bashrcRun the following command to allow the changes to take effect:
source ~/.bashrcRun the following commands to check whether the environment variables take effect:
echo $TABLESTORE_ACCESS_KEY_ID echo $TABLESTORE_ACCESS_KEY_SECRET
macOS
Run the following command in the terminal to check the default Shell type.
echo $SHELLPerform operations based on the default Shell type.
Zsh
Run the following commands to append environment variable settings to the
~/.zshrcfile.echo "export TABLESTORE_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.zshrc echo "export TABLESTORE_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.zshrcRun the following command to allow the changes to take effect:
source ~/.zshrcRun the following commands to check whether the environment variables take effect:
echo $TABLESTORE_ACCESS_KEY_ID echo $TABLESTORE_ACCESS_KEY_SECRET
Bash
Run the following commands to append environment variable settings to the
~/.bash_profilefile.echo "export TABLESTORE_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.bash_profile echo "export TABLESTORE_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.bash_profileRun the following command to allow the changes to take effect:
source ~/.bash_profileRun the following commands to check whether the environment variables take effect:
echo $TABLESTORE_ACCESS_KEY_ID echo $TABLESTORE_ACCESS_KEY_SECRET
Windows
CMD
Run the following commands in CMD to set environment variables.
setx TABLESTORE_ACCESS_KEY_ID "YOUR_ACCESS_KEY_ID" setx TABLESTORE_ACCESS_KEY_SECRET "YOUR_ACCESS_KEY_SECRET"After restarting CMD, run the following commands to check whether the environment variables take effect:
echo %TABLESTORE_ACCESS_KEY_ID% echo %TABLESTORE_ACCESS_KEY_SECRET%
PowerShell
Run the following command in PowerShell:
[Environment]::SetEnvironmentVariable("TABLESTORE_ACCESS_KEY_ID", "YOUR_ACCESS_KEY_ID", [EnvironmentVariableTarget]::User) [Environment]::SetEnvironmentVariable("TABLESTORE_ACCESS_KEY_SECRET", "YOUR_ACCESS_KEY_SECRET", [EnvironmentVariableTarget]::User)Run the following commands to check whether the environment variables take effect:
[Environment]::GetEnvironmentVariable("TABLESTORE_ACCESS_KEY_ID", [EnvironmentVariableTarget]::User) [Environment]::GetEnvironmentVariable("TABLESTORE_ACCESS_KEY_SECRET", [EnvironmentVariableTarget]::User)
Install the Tablestore SDK for your preferred programming language.
Java
If you use a Maven project, add the following dependency to your pom.xml file:
<dependency> <groupId>com.aliyun.openservices</groupId> <artifactId>tablestore</artifactId> <version>5.17.4</version> </dependency>For more information, see Install Tablestore SDK for Java.
Go
Run the
go mod init <DIRNAME>command in the project directory to generate the go.mo d file. Then, run the following command to install Tablestore SDK for Go:Note<DIRNAME>indicates the project directory path. Replace <DIRNAME> with the actual project directory path.go get github.com/aliyun/aliyun-tablestore-go-sdk/tablestoreFor more information, see Install Tablestore SDK for Go.
Python
Run the following command to use pip to install Tablestore SDK for Python:
sudo pip install tablestoreFor more information, see Install Tablestore SDK for Python.
Node.js
Run the following command to install the Tablestore SDK for Node.js:
npm install tablestoreFor more information, see Install Tablestore SDK for Node.js.
.NET
For more information, see Install Tablestore .NET SDK.
PHP
For more information, see Install Tablestore PHP SDK.
Wide column model
To use the wide column model, initialize the client with the RAM user's AccessKey pair.
Java
V4 signature
The following Java sample code shows how to use a V4 signature to initialize a client and retrieve the names of all data tables in an instance.
import com.alicloud.openservices.tablestore.ClientConfiguration;
import com.alicloud.openservices.tablestore.SyncClient;
import com.alicloud.openservices.tablestore.core.ResourceManager;
import com.alicloud.openservices.tablestore.core.auth.CredentialsProvider;
import com.alicloud.openservices.tablestore.core.auth.DefaultCredentialProvider;
import com.alicloud.openservices.tablestore.core.auth.DefaultCredentials;
import com.alicloud.openservices.tablestore.core.auth.V4Credentials;
import com.alicloud.openservices.tablestore.model.AlwaysRetryStrategy;
import com.alicloud.openservices.tablestore.model.ListTableResponse;
public class InitClientV4 {
public static void main(String[] args) {
// Replace yourRegion with the region where your instance is located, for example, cn-hangzhou.
final String region = "yourRegion";
// Replace yourInstanceName with the name of your instance.
final String instanceName = "yourInstanceName";
// Replace yourEndpoint with the endpoint of your instance.
final String endpoint = "yourEndpoint";
// Obtain the AccessKey ID and AccessKey secret from environment variables.
final String accessKeyId = System.getenv("TABLESTORE_ACCESS_KEY_ID");
final String accessKeySecret = System.getenv("TABLESTORE_ACCESS_KEY_SECRET");
// Construct a V4 signature.
DefaultCredentials credentials = new DefaultCredentials(accessKeyId, accessKeySecret);
V4Credentials credentialsV4 = V4Credentials.createByServiceCredentials(credentials, region);
CredentialsProvider provider = new DefaultCredentialProvider(credentialsV4);
// Initialize the Tablestore client.
SyncClient client = new SyncClient(endpoint, provider, instanceName, null, new ResourceManager(null, null));
/*
// You can specify a ClientConfiguration to modify the default settings. The following example shows some custom settings.
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setConnectionTimeoutInMillisecond(5000); // Set the connection timeout period in milliseconds.
clientConfiguration.setSocketTimeoutInMillisecond(5000); // Set the socket timeout period in milliseconds.
clientConfiguration.setRetryStrategy(new AlwaysRetryStrategy()); // Set a retry policy. If a retry policy is not set, the default retry policy is used.
SyncClient client = new SyncClient(endpoint, provider, instanceName, clientConfiguration, new ResourceManager(null, null));
*/
// List the data tables in the instance and print their names to the console.
ListTableResponse listTableResponse = client.listTable();
listTableResponse.getTableNames().forEach(System.out::println);
// Shut down the Tablestore client.
client.shutdown();
}
}V2 signature
The following Java sample code shows how to use a V2 signature to initialize a client and retrieve the names of all data tables in an instance.
import com.alicloud.openservices.tablestore.ClientConfiguration;
import com.alicloud.openservices.tablestore.SyncClient;
import com.alicloud.openservices.tablestore.core.ResourceManager;
import com.alicloud.openservices.tablestore.core.auth.CredentialsProvider;
import com.alicloud.openservices.tablestore.core.auth.DefaultCredentialProvider;
import com.alicloud.openservices.tablestore.core.auth.DefaultCredentials;
import com.alicloud.openservices.tablestore.model.AlwaysRetryStrategy;
import com.alicloud.openservices.tablestore.model.ListTableResponse;
public class InitClientV2 {
public static void main(String[] args) {
// Replace yourInstanceName with the name of your instance.
final String instanceName = "yourInstanceName";
// Replace yourEndpoint with the endpoint of your instance.
final String endpoint = "yourEndpoint";
// Obtain the AccessKey ID and AccessKey secret from environment variables.
final String accessKeyId = System.getenv("TABLESTORE_ACCESS_KEY_ID");
final String accessKeySecret = System.getenv("TABLESTORE_ACCESS_KEY_SECRET");
// Construct a V2 signature.
DefaultCredentials credentials = new DefaultCredentials(accessKeyId, accessKeySecret);
CredentialsProvider provider = new DefaultCredentialProvider(credentials);
// Initialize the Tablestore client.
SyncClient client = new SyncClient(endpoint, provider, instanceName, null, new ResourceManager(null, null));
/*
// You can specify a ClientConfiguration to modify the default settings. The following example shows some custom settings.
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setConnectionTimeoutInMillisecond(5000); // Set the connection timeout period in milliseconds.
clientConfiguration.setSocketTimeoutInMillisecond(5000); // Set the socket timeout period in milliseconds.
clientConfiguration.setRetryStrategy(new AlwaysRetryStrategy()); // Set a retry policy. If a retry policy is not set, the default retry policy is used.
SyncClient client = new SyncClient(endpoint, provider, instanceName, clientConfiguration, new ResourceManager(null, null));
*/
// List the data tables in the instance and print their names to the console.
ListTableResponse listTableResponse = client.listTable();
listTableResponse.getTableNames().forEach(System.out::println);
// Shut down the Tablestore client.
client.shutdown();
}
}Go
The following Go sample code shows how to initialize a client and retrieve the names of all data tables in an instance.
package main
import (
"fmt"
"os"
"github.com/aliyun/aliyun-tablestore-go-sdk/tablestore"
)
func main() {
// Replace yourInstanceName with the name of your instance.
instanceName := "yourInstanceName"
// Replace yourEndpoint with the endpoint of your instance.
endpoint := "yourEndpoint"
// Obtain the AccessKey ID and AccessKey secret from environment variables.
accessKeyId := os.Getenv("TABLESTORE_ACCESS_KEY_ID")
accessKeySecret := os.Getenv("TABLESTORE_ACCESS_KEY_SECRET")
// Initialize the Tablestore client.
client := tablestore.NewClient(endpoint, instanceName, accessKeyId, accessKeySecret)
// List the data tables in the instance and print their names to the console.
tables, err := client.ListTable()
if err != nil {
fmt.Println("Failed to list table")
} else {
for _, table := range (tables.TableNames) {
fmt.Println(table)
}
}
}Python
The following Python sample code shows how to initialize a client and retrieve the names of all data tables in an instance.
# -*- coding: utf-8 -*-
import os
from tablestore import OTSClient
# Replace yourInstanceName with the name of your instance.
instance_name = "yourInstanceName"
# Replace yourEndpoint with the endpoint of your instance.
endpoint = "yourEndpoint"
# Obtain the AccessKey ID and AccessKey secret from environment variables.
access_key_id = os.getenv("TABLESTORE_ACCESS_KEY_ID")
access_key_secret = os.getenv("TABLESTORE_ACCESS_KEY_SECRET")
# Initialize the Tablestore client.
client = OTSClient(endpoint, access_key_id, access_key_secret, instance_name)
# List the data tables in the instance and print their names to the console.
resp = client.list_table()
for table_name in resp:
print(table_name)Node.js
The following Node.js sample code shows how to initialize a client and retrieve the names of all data tables in an instance.
// This is a relative path. Adjust it based on your actual file structure.
var TableStore = require('../index.js');
// Replace yourInstanceName with the name of your instance.
var instancename = 'yourInstanceName';
// Replace yourEndpoint with the endpoint of your instance.
var endpoint = 'yourEndpoint';
// Obtain the AccessKey ID and AccessKey secret from environment variables.
var accessKeyId = process.env.TABLESTORE_ACCESS_KEY_ID;
var secretAccessKey = process.env.TABLESTORE_ACCESS_KEY_SECRET;
// Initialize the Tablestore client.
var client = new TableStore.Client({
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
endpoint: endpoint,
instancename: instancename
});
// List the data tables in the instance and print their names to the console.
client.listTable({}, function (err, data) {
if (err) {
console.log('error:', err);
return;
}
console.log('success:', data);
}); .NET
The following .NET sample code shows how to initialize a client and retrieve the names of all data tables in an instance.
using Aliyun.OTS.Request;
using Aliyun.OTS.Response;
using System;
namespace Aliyun.OTS.Samples
{
public class Sample
{
public static void InitializeClient()
{
// Replace yourEndpoint with the endpoint of your instance.
string endpoint = "yourEndpoint";
// Replace yourInstanceName with the name of your instance.
string instanceName = "yourInstanceName";
// Obtain the AccessKey ID and AccessKey secret from environment variables.
string accessKeyId = Environment.GetEnvironmentVariable("TABLESTORE_ACCESS_KEY_ID");
string accessKeySecret = Environment.GetEnvironmentVariable("TABLESTORE_ACCESS_KEY_SECRET");
OTSClientConfig config = new OTSClientConfig(endpoint, accessKeyId, accessKeySecret, instanceName)
{
OTSDebugLogHandler = null,
OTSErrorLogHandler = null
};
try
{
// Initialize the Tablestore client.
OTSClient client = new OTSClient(config);
// List the data tables in the instance and print their names.
ListTableResponse response = client.ListTable(new ListTableRequest());
foreach (var tableName in response.TableNames)
{
Console.WriteLine(tableName);
}
}
catch (Exception ex)
{
Console.WriteLine("List table failed, exception:{0}", ex.Message);
}
}
}
}PHP
The following PHP sample code shows how to initialize a client and retrieve the names of all data tables in an instance.
<?php
// This is a relative path. Adjust it based on your actual file structure.
require (__DIR__ . '/../../vendor/autoload.php');
use Aliyun\OTS\OTSClient as OTSClient;
// Replace yourInstanceName with the name of your instance.
$instanceName = "yourInstanceName";
// Replace yourEndpoint with the endpoint of your instance.
$endpoint = "yourEndpoint";
// Obtain the AccessKey ID and AccessKey secret from system environment variables.
$accessKeyId = getenv('TABLESTORE_ACCESS_KEY_ID');
$accessKeySecret = getenv('TABLESTORE_ACCESS_KEY_SECRET');
// Initialize the Tablestore client.
$client = new OTSClient(array(
'EndPoint' => $endpoint,
'AccessKeyID' => $accessKeyId,
'AccessKeySecret' => $accessKeySecret,
'InstanceName' => $instanceName,
));
// List the data tables in the instance and print their names to the console.
$response = $client->listTable (array ());
print json_encode ($response);Time series model
To use the time series model, initialize the client with the RAM user's AccessKey pair. Currently, the time series model is supported by the SDKs for Java, Go, and Python.
Java
V4 signature
The following Java sample code shows how to use a V4 signature to initialize a client and retrieve the names of all time series tables in an instance.
import com.alicloud.openservices.tablestore.ClientConfiguration;
import com.alicloud.openservices.tablestore.TimeseriesClient;
import com.alicloud.openservices.tablestore.core.ResourceManager;
import com.alicloud.openservices.tablestore.core.auth.CredentialsProvider;
import com.alicloud.openservices.tablestore.core.auth.DefaultCredentialProvider;
import com.alicloud.openservices.tablestore.core.auth.DefaultCredentials;
import com.alicloud.openservices.tablestore.core.auth.V4Credentials;
import com.alicloud.openservices.tablestore.model.AlwaysRetryStrategy;
import com.alicloud.openservices.tablestore.model.timeseries.ListTimeseriesTableResponse;
public class InitTimeseriesClientV4 {
public static void main(String[] args) {
// Replace yourRegion with the region where your instance is located, for example, cn-hangzhou.
final String region = "yourRegion";
// Replace yourInstanceName with the name of your instance.
final String instanceName = "yourInstanceName";
// Replace yourEndpoint with the endpoint of your instance.
final String endpoint = "yourEndpoint";
// Obtain the AccessKey ID and AccessKey secret from environment variables.
final String accessKeyId = System.getenv("TABLESTORE_ACCESS_KEY_ID");
final String accessKeySecret = System.getenv("TABLESTORE_ACCESS_KEY_SECRET");
// Construct a V4 signature.
DefaultCredentials credentials = new DefaultCredentials(accessKeyId, accessKeySecret);
V4Credentials credentialsV4 = V4Credentials.createByServiceCredentials(credentials, region);
CredentialsProvider provider = new DefaultCredentialProvider(credentialsV4);
// Initialize the Tablestore client.
TimeseriesClient client = new TimeseriesClient(endpoint, provider, instanceName, null, new ResourceManager(null, null));
/*
// You can specify a ClientConfiguration to modify the default settings. The following example shows some custom settings.
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setConnectionTimeoutInMillisecond(5000); // Set the connection timeout period in milliseconds.
clientConfiguration.setSocketTimeoutInMillisecond(5000); // Set the socket timeout period in milliseconds.
clientConfiguration.setRetryStrategy(new AlwaysRetryStrategy()); // Set a retry policy. If a retry policy is not set, the default retry policy is used.
TimeseriesClient client = new TimeseriesClient(endpoint, provider, instanceName, clientConfiguration, new ResourceManager(null, null));
*/
// List the time series tables in the instance and print their names to the console.
ListTimeseriesTableResponse listTimeseriesTableResponse = client.listTimeseriesTable();
listTimeseriesTableResponse.getTimeseriesTableNames().forEach(System.out::println);
// Shut down the Tablestore client.
client.shutdown();
}
}V2 signature
The following Java sample code shows how to use a V2 signature to initialize a client and retrieve the names of all time series tables in an instance.
import com.alicloud.openservices.tablestore.ClientConfiguration;
import com.alicloud.openservices.tablestore.TimeseriesClient;
import com.alicloud.openservices.tablestore.core.ResourceManager;
import com.alicloud.openservices.tablestore.core.auth.CredentialsProvider;
import com.alicloud.openservices.tablestore.core.auth.DefaultCredentialProvider;
import com.alicloud.openservices.tablestore.core.auth.DefaultCredentials;
import com.alicloud.openservices.tablestore.model.AlwaysRetryStrategy;
import com.alicloud.openservices.tablestore.model.timeseries.ListTimeseriesTableResponse;
public class InitTimeseriesClientV2 {
public static void main(String[] args) {
// Replace yourInstanceName with the name of your instance.
final String instanceName = "yourInstanceName";
// Replace yourEndpoint with the endpoint of your instance.
final String endpoint = "yourEndpoint";
// Obtain the AccessKey ID and AccessKey secret from environment variables.
final String accessKeyId = System.getenv("TABLESTORE_ACCESS_KEY_ID");
final String accessKeySecret = System.getenv("TABLESTORE_ACCESS_KEY_SECRET");
// Construct a V2 signature.
DefaultCredentials credentials = new DefaultCredentials(accessKeyId, accessKeySecret);
CredentialsProvider provider = new DefaultCredentialProvider(credentials);
// Initialize the Tablestore client.
TimeseriesClient client = new TimeseriesClient(endpoint, provider, instanceName, null, new ResourceManager(null, null));
/*
// You can specify a ClientConfiguration to modify the default settings. The following example shows some custom settings.
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setConnectionTimeoutInMillisecond(5000); // Set the connection timeout period in milliseconds.
clientConfiguration.setSocketTimeoutInMillisecond(5000); // Set the socket timeout period in milliseconds.
clientConfiguration.setRetryStrategy(new AlwaysRetryStrategy()); // Set a retry policy. If a retry policy is not set, the default retry policy is used.
TimeseriesClient client = new TimeseriesClient(endpoint, provider, instanceName, clientConfiguration, new ResourceManager(null, null));
*/
// List the time series tables in the instance and print their names to the console.
ListTimeseriesTableResponse listTimeseriesTableResponse = client.listTimeseriesTable();
listTimeseriesTableResponse.getTimeseriesTableNames().forEach(System.out::println);
// Shut down the Tablestore client.
client.shutdown();
}
}Go
The following Go sample code shows how to initialize a client and retrieve the names of all time series tables in an instance.
package main
import (
"fmt"
"os"
"github.com/aliyun/aliyun-tablestore-go-sdk/tablestore"
)
func main() {
// Replace yourInstanceName with the name of your instance.
instanceName := "yourInstanceName"
// Replace yourEndpoint with the endpoint of your instance.
endpoint := "yourEndpoint"
// Obtain the AccessKey ID and AccessKey secret from environment variables.
accessKeyId := os.Getenv("TABLESTORE_ACCESS_KEY_ID")
accessKeySecret := os.Getenv("TABLESTORE_ACCESS_KEY_SECRET")
// Initialize the Tablestore client.
client := tablestore.NewTimeseriesClient(endpoint, instanceName, accessKeyId, accessKeySecret)
// List the time series tables in the instance and print their names to the console.
timeseriesTables, err := client.ListTimeseriesTable()
if err != nil {
fmt.Println("Failed to list table")
} else {
for _, timeseriesTablesMeta := range (timeseriesTables.GetTimeseriesTableMeta()) {
fmt.Println(timeseriesTablesMeta.GetTimeseriesTableName())
}
}
}Python
The following Python sample code shows how to initialize a client and retrieve the names of all time series tables in an instance.
# -*- coding: utf-8 -*-
import os
from tablestore import OTSClient
# Replace yourInstanceName with the name of your instance.
instance_name = "yourInstanceName"
# Replace yourEndpoint with the endpoint of your instance.
endpoint = "yourEndpoint"
# Obtain the AccessKey ID and AccessKey secret from environment variables.
access_key_id = os.getenv("TABLESTORE_ACCESS_KEY_ID")
access_key_secret = os.getenv("TABLESTORE_ACCESS_KEY_SECRET")
# Initialize the Tablestore client.
client = OTSClient(endpoint, access_key_id, access_key_secret, instance_name)
# List the time series tables in the instance and print their names to the console.
response = client.list_timeseries_table()
for tableMeta in response:
print(tableMeta.timeseries_table_name)