Resource Access Management (RAM), kullanıcı kimliklerini ve kaynak erişim izinlerini yönetmenize yardımcı olur. Gelişmiş güvenlik için, Alibaba Cloud hesap kimlik bilgilerinizi kullanmak yerine bir RAM kullanıcısının AccessKey çiftini kullanarak Tablestore kaynaklarına erişmek daha güvenlidir. Bu konuda, bir RAM kullanıcısının AccessKey çiftini kullanarak Tablestore kaynaklarına nasıl erişeceğiniz açıklanmaktadır.
Arka Plan
Bir RAM kullanıcısı, Resource Access Management (RAM) içindeki bir kimlik türüdür. Alibaba Cloud hesabınız altında RAM kullanıcıları oluşturabilir ve onlara belirli izinler verebilirsiniz. Bu sayede farklı RAM kullanıcılarının kaynaklarınıza farklı erişim seviyelerine sahip olmasını sağlayabilirsiniz.
Yordam
Bir RAM kullanıcısının AccessKey çifti ile Tablestore hizmetine erişmek için öncelikle bir RAM kullanıcısı oluşturun, bu kullanıcıya Tablestore erişim izinleri verin ve ardından kullanıcının AccessKey bilgilerini kullanarak Tablestore kaynaklarına erişin.
Adım 1: RAM kullanıcısı oluşturun
Yönetici izinlerine sahip bir Alibaba Cloud hesabı veya RAM kullanıcısı kullanarak RAM konsolunda oturum açın.
Sol gezinme bölmesinde, Identities > Users seçeneğini belirleyin.
Users sayfasında Create User düğmesine tıklayın.
-
Create User sayfasındaki User Account Information bölümünde kullanıcının temel bilgilerini yapılandırın:
Logon Name: Oturum açma adı harf, rakam, nokta (.), kısa çizgi (-) ve alt çizgi (_) içerebilir. Uzunluğu en fazla 64 karakter olabilir.
Display Name: Görünen adın uzunluğu en fazla 128 karakter olabilir.
Tag:
simgesine tıklayın ve bir etiket anahtarı ile etiket değeri girin. Etiket eklemek, RAM kullanıcısını bulmanıza ve yönetmenize yardımcı olur.
NotBirden çok RAM kullanıcısını toplu olarak oluşturmak için Add User düğmesine tıklayabilirsiniz.
-
Access Mode bölümünde Programmatic Access seçeneğini belirleyin ve ardından OK düğmesine tıklayın.
NotRAM kullanıcısının Alibaba Cloud Management Console'da oturum açmasına izin vermek için Console Access seçeneğini belirleyin.
-
Actions sütununda RAM kullanıcısı bilgilerini kaydetmek için Copy seçeneğine tıklayın. AccessKey ID ve AccessKey secret değerlerini ayrı ayrı da kopyalayabilirsiniz.
ÖnemliAccessKey secret yalnızca oluşturma sırasında bir kez gösterilir ve daha sonra alınamaz. Bu bilgiyi hemen güvenli bir konumda saklayın.
Adım 2: RAM kullanıcısına Tablestore izinleri verin
Bir RAM kullanıcısı oluşturduktan sonra, bu kullanıcıya Tablestore erişim izinleri vermeniz gerekir.
Varsayılan ilke
Bu örnekte, AliyunOTSFullAccess ilkesini ekleyerek bir RAM kullanıcısına Tablestore erişim izinlerinin nasıl verileceği gösterilmektedir.
AliyunOTSFullAccess ilkesi, Tablestore üzerinde tam erişim sağlar. İzinleri diğer varsayılan ilkeleri kullanarak da verebilirsiniz:
Salt okunur erişim için RAM kullanıcısına
AliyunOTSReadOnlyAccessilkesini verin.Salt yazma erişimi için RAM kullanıcısına
AliyunOTSWriteOnlyAccessilkesini verin.
Sol gezinme bölmesinde, Identities > Users seçeneğini belirleyin.
Users sayfasında hedef RAM kullanıcısını bulun.
RAM kullanıcısının Actions sütunundaki Add Permissions seçeneğine tıklayın.
Grant Permission panelindeki Policy bölümünde
AliyunOTSFullAccessilkesini aratın ve seçin.Grant Permissions düğmesine tıklayın.
Özel ilke
-
Özel bir ilke oluşturun.
Sol gezinme bölmesinde Permissions > Policies seçeneğini belirleyin.
Policies sayfasında Create Policy düğmesine tıklayın.
-
Create Policy sayfasında JSON sekmesine tıklayın, düzenleyiciye ilke betiğinizi girin ve ardından OK düğmesine tıklayın.
NotAşağıdaki örnek betik, bir RAM kullanıcısına tek bir örneğe erişim izni verir. Erişimi tablo veya API işlemi düzeyinde ya da IP adresi veya erişim zamanı gibi koşullara göre kontrol etmek için ilkeyi özelleştirebilirsiniz. RAM ilkeleri hakkında daha fazla bilgi için bkz. Özel RAM ilkesi.
{ "Version": "1", "Statement": [ { "Effect": "Allow", "Action": "ots:*", "Resource": "acs:ots:*:*:instance/your_instance_name*" } ] } Create Policy iletişim kutusunda
TestRAMPolicygibi bir ilke adı girin ve ardından OK düğmesine tıklayın.
-
Özel ilkeyi RAM kullanıcısına ekleyin.
Sol gezinme bölmesinde, Identities > Users seçeneğini belirleyin.
Users sayfasında hedef RAM kullanıcısını bulun.
RAM kullanıcısının Actions sütunundaki Add Permissions seçeneğine tıklayın.
Grant Permission panelindeki Policy bölümünde oluşturduğunuz özel ilkeyi aratın ve seçin.
Grant Permissions düğmesine tıklayın.
Users sayfasında, kullanıcı adına tıklayarak kullanıcı ayrıntıları sayfasına gidebilirsiniz. Permissions sekmesinde, kullanıcıya verilen ilkeleri görüntüleyebilirsiniz.
Adım 3: Tablestore hizmetine erişmek için AccessKey çiftini kullanın
Başlamadan önce
Tablestore konsolunda bir örnek ve bir veri tablosu oluşturun.
-
Örnek adını, uç noktayı ve bölge kimliğini edinin.
ÖnemliVarsayılan olarak, yeni oluşturulan örnekler için genel ağ erişimi devre dışı bırakılır. Bir örnekteki kaynaklara internet üzerinden erişmeniz gerekiyorsa, örnek için genel ağ erişimini etkinleştirmeniz gerekir.
-
Ortam değişkenlerini yapılandırın. Yapılandırma tamamlandıktan sonra, en son sistem ortam değişkenlerinin başarıyla yüklendiğinden emin olmak için IDE, komut satırı arabirimi, diğer masaüstü uygulamaları ve arka plan hizmetleri dahil olmak üzere derleme ve çalışma zamanı ortamınızı yeniden başlatın veya yenileyin.
Linux
-
Komut satırı arabiriminde aşağıdaki komutları çalıştırarak ortam değişkeni ayarlarını
~/.bashrcdosyasına ekleyin.echo "export TABLESTORE_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.bashrc echo "export TABLESTORE_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.bashrc -
Değişikliklerin etkili olması için aşağıdaki komutu çalıştırın:
source ~/.bashrc -
Ortam değişkenlerinin etkili olup olmadığını kontrol etmek için aşağıdaki komutları çalıştırın:
echo $TABLESTORE_ACCESS_KEY_ID echo $TABLESTORE_ACCESS_KEY_SECRET
macOS
-
Terminalde varsayılan Shell türünü kontrol etmek için aşağıdaki komutu çalıştırın.
echo $SHELL -
Varsayılan Shell türüne göre işlemleri gerçekleştirin.
Zsh
-
Aşağıdaki komutları çalıştırarak ortam değişkeni ayarlarını
~/.zshrcdosyasına ekleyin.echo "export TABLESTORE_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.zshrc echo "export TABLESTORE_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.zshrc -
Değişikliklerin etkili olması için aşağıdaki komutu çalıştırın:
source ~/.zshrc -
Ortam değişkenlerinin etkili olup olmadığını kontrol etmek için aşağıdaki komutları çalıştırın:
echo $TABLESTORE_ACCESS_KEY_ID echo $TABLESTORE_ACCESS_KEY_SECRET
Bash
-
Aşağıdaki komutları çalıştırarak ortam değişkeni ayarlarını
~/.bash_profiledosyasına ekleyin.echo "export TABLESTORE_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.bash_profile echo "export TABLESTORE_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.bash_profile -
Değişikliklerin etkili olması için aşağıdaki komutu çalıştırın:
source ~/.bash_profile -
Ortam değişkenlerinin etkili olup olmadığını kontrol etmek için aşağıdaki komutları çalıştırın:
echo $TABLESTORE_ACCESS_KEY_ID echo $TABLESTORE_ACCESS_KEY_SECRET
-
Windows
CMD
-
Ortam değişkenlerini ayarlamak için CMD'de aşağıdaki komutları çalıştırın.
setx TABLESTORE_ACCESS_KEY_ID "YOUR_ACCESS_KEY_ID" setx TABLESTORE_ACCESS_KEY_SECRET "YOUR_ACCESS_KEY_SECRET" -
CMD'yi yeniden başlattıktan sonra, ortam değişkenlerinin etkili olup olmadığını kontrol etmek için aşağıdaki komutları çalıştırın:
echo %TABLESTORE_ACCESS_KEY_ID% echo %TABLESTORE_ACCESS_KEY_SECRET%
PowerShell
-
PowerShell'de aşağıdaki komutu çalıştırın:
[Environment]::SetEnvironmentVariable("TABLESTORE_ACCESS_KEY_ID", "YOUR_ACCESS_KEY_ID", [EnvironmentVariableTarget]::User) [Environment]::SetEnvironmentVariable("TABLESTORE_ACCESS_KEY_SECRET", "YOUR_ACCESS_KEY_SECRET", [EnvironmentVariableTarget]::User) -
Ortam değişkenlerinin etkili olup olmadığını kontrol etmek için aşağıdaki komutları çalıştırın:
[Environment]::GetEnvironmentVariable("TABLESTORE_ACCESS_KEY_ID", [EnvironmentVariableTarget]::User) [Environment]::GetEnvironmentVariable("TABLESTORE_ACCESS_KEY_SECRET", [EnvironmentVariableTarget]::User)
-
-
Tercih ettiğiniz programlama dili için Tablestore SDK'sını yükleyin.
Java
Bir Maven projesi kullanıyorsanız, pom.xml dosyanıza aşağıdaki bağımlılığı ekleyin:
<dependency> <groupId>com.aliyun.openservices</groupId> <artifactId>tablestore</artifactId> <version>5.17.4</version> </dependency>
Daha fazla bilgi için bkz. Java için Tablestore SDK'sını yükleme.
Go
Proje dizininde go.mod dosyasını oluşturmak için
go mod init <DIRNAME>komutunu çalıştırın. Ardından, Go için Tablestore SDK'sını yüklemek için aşağıdaki komutu çalıştırın:Not<DIRNAME>proje dizini yolunu belirtir. <DIRNAME> ifadesini gerçek proje dizini yolu ile değiştirin.go get github.com/aliyun/aliyun-tablestore-go-sdk/tablestoreDaha fazla bilgi için bkz. Go için Tablestore SDK'sını yükleme.
Python
Python için Tablestore SDK'sını pip kullanarak yüklemek için aşağıdaki komutu çalıştırın:
sudo pip install tablestoreDaha fazla bilgi için bkz. Python için Tablestore SDK'sını yükleme.
Node.js
Node.js için Tablestore SDK'sını yüklemek için aşağıdaki komutu çalıştırın:
npm install tablestoreDaha fazla bilgi için bkz. Node.js için Tablestore SDK'sını yükleme.
.NET
Daha fazla bilgi için bkz. Tablestore .NET SDK'sını yükleme.
PHP
Daha fazla bilgi için bkz. Tablestore PHP SDK'sını yükleme.
Geniş sütun modeli
Geniş sütun modelini kullanmak için istemciyi RAM kullanıcısının AccessKey çifti ile başlatın.
Java
V4 imzası
Aşağıdaki Java örnek kodu, bir istemciyi V4 imzası kullanarak başlatmayı ve bir örnekteki tüm veri tablolarının adlarını almayı göstermektedir.
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 imzası
Aşağıdaki Java örnek kodu, bir istemciyi V2 imzası kullanarak başlatmayı ve bir örnekteki tüm veri tablolarının adlarını almayı göstermektedir.
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
Aşağıdaki Go örnek kodu, bir istemciyi başlatmayı ve bir örnekteki tüm veri tablolarının adlarını almayı göstermektedir.
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
Aşağıdaki Python örnek kodu, bir istemciyi başlatmayı ve bir örnekteki tüm veri tablolarının adlarını almayı göstermektedir.
# -*- 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
Aşağıdaki Node.js örnek kodu, bir istemciyi başlatmayı ve bir örnekteki tüm veri tablolarının adlarını almayı göstermektedir.
// 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
Aşağıdaki .NET örnek kodu, bir istemciyi başlatmayı ve bir örnekteki tüm veri tablolarının adlarını almayı göstermektedir.
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
Aşağıdaki PHP örnek kodu, bir istemciyi başlatmayı ve bir örnekteki tüm veri tablolarının adlarını almayı göstermektedir.
<?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);
Zaman serisi modeli
Zaman serisi modelini kullanmak için istemciyi RAM kullanıcısının AccessKey çifti ile başlatın. Şu anda zaman serisi modeli Java, Go ve Python SDK'ları tarafından desteklenmektedir.
Java
V4 imzası
Aşağıdaki Java örnek kodu, bir istemciyi V4 imzası kullanarak başlatmayı ve bir örnekteki tüm zaman serisi tablolarının adlarını almayı göstermektedir.
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 imzası
Aşağıdaki Java örnek kodu, bir istemciyi V2 imzası kullanarak başlatmayı ve bir örnekteki tüm zaman serisi tablolarının adlarını almayı göstermektedir.
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
Aşağıdaki Go örnek kodu, bir istemciyi başlatmayı ve bir örnekteki tüm zaman serisi tablolarının adlarını almayı göstermektedir.
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
Aşağıdaki Python örnek kodu, bir istemciyi başlatmayı ve bir örnekteki tüm zaman serisi tablolarının adlarını almayı göstermektedir.
# -*- 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)