alibabacloud-tablestore-ops
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTablestore Read-Only Operations
Tablestore 只读操作
This skill provides CLI-based read-only operations for querying Alibaba Cloud Tablestore (OTS) instances and data tables. Tablestore is a fully managed NoSQL database service that supports storing and accessing large amounts of structured data.
Architecture:
Aliyun CLI (otsutil) → Tablestore Instance → Data Tables (Wide Table / TimeSeries)Scope: This skill only covers read/query operations. No create, update, or delete operations are included.
本Skill提供基于CLI的只读操作能力,用于查询阿里云Tablestore(OTS)实例和数据表。Tablestore是一款全托管NoSQL数据库服务,支持存储和访问海量结构化数据。
架构:
Aliyun CLI (otsutil) → Tablestore Instance → Data Tables (Wide Table / TimeSeries)适用范围: 本Skill仅覆盖读取/查询操作,不包含任何创建、更新或删除操作。
Prerequisites
前提条件
- Tablestore service must be activated. See Alibaba Cloud Console
- Obtain AccessKey ID and AccessKey Secret from RAM Console
Pre-check: Aliyun CLI Required (Version 3.3.0+)Tablestore operations are performed viacommand, which is part of the Aliyun CLI. IMPORTANT: Thealiyun otsutilsubcommand is only available in Aliyun CLI version 3.3.0 or later. The Homebrew version may be outdated - download directly from the official CDN. See references/cli-installation-guide.md for installation instructions.otsutil
Installation
安装
Install Aliyun CLI (Version 3.3.0+)
安装Aliyun CLI(3.3.0及以上版本)
WARNING: The Homebrew version () may not includebrew install aliyun-cli. Always download from the official CDN to ensure you get version 3.3.0+ with otsutil support.otsutil
Option 1: Download Binary (Recommended)
| Platform | Download |
|---|---|
| Mac (Universal) | Mac Universal |
| Linux (AMD64) | Linux AMD64 |
| Linux (ARM64) | Linux ARM64 |
| Windows (64-bit) | Windows |
Option 2: Mac GUI Installer
Download Mac PKG and double-click to install.
警告: 通过Homebrew安装的版本()可能不包含brew install aliyun-cli。 请始终从官方CDN下载,确保获得支持otsutil的3.3.0及以上版本。otsutil
方案1:下载二进制文件(推荐)
| 平台 | 下载地址 |
|---|---|
| Mac (通用版) | Mac Universal |
| Linux (AMD64) | Linux AMD64 |
| Linux (ARM64) | Linux ARM64 |
| Windows (64位) | Windows |
方案2:Mac GUI安装程序
下载Mac PKG安装包,双击完成安装。
macOS / Linux Binary Setup
macOS / Linux 二进制文件配置
bash
undefinedbash
undefinedDownload (example for macOS Universal)
下载(以macOS通用版为例)
curl -L -o aliyun-cli.tgz https://aliyuncli.alicdn.com/aliyun-cli-macosx-latest-universal.tgz
curl -L -o aliyun-cli.tgz https://aliyuncli.alicdn.com/aliyun-cli-macosx-latest-universal.tgz
Extract
解压
tar -xzf aliyun-cli.tgz
tar -xzf aliyun-cli.tgz
Move to PATH
移动到PATH目录
sudo mv aliyun /usr/local/bin/
sudo mv aliyun /usr/local/bin/
Verify installation and version (must be 3.3.0+)
验证安装和版本(必须为3.3.0及以上)
aliyun version
aliyun version
Verify otsutil is available
验证otsutil可用
aliyun otsutil help
undefinedaliyun otsutil help
undefinedWindows Setup
Windows 配置
- Download the zip file from the download link above
- Extract the zip file to get
aliyun.exe - Add the directory to your PATH environment variable
- Verify: (must show 3.3.0 or later)
aliyun version
- 从上方下载链接获取zip压缩包
- 解压得到文件
aliyun.exe - 将文件所在目录添加到PATH环境变量
- 验证:(必须显示3.3.0或更高版本)
aliyun version
Parameter Confirmation
参数确认
IMPORTANT: Parameter Confirmation — Before executing any command, ALL user-customizable parameters (e.g., RegionId, instance names, AccessKey, endpoint, etc.) MUST be confirmed with the user. Do NOT assume or use default values without explicit user approval.
| Parameter | Required | Description | Default |
|---|---|---|---|
| Yes (for table ops) | Instance endpoint URL | - |
| Yes (for table ops) | Instance name | - |
| Yes (for describe_instance) | Instance name | - |
| Yes (for instance ops) | Region ID (e.g., cn-hangzhou) | - |
| Yes (for table ops) | Data table name | - |
Note: AccessKey credentials are configured via, not passed as command parameters.aliyun configure
重要提示:参数确认 — 执行任何命令前,所有用户可自定义参数(例如RegionId、实例名、AccessKey、endpoint等)必须与用户确认。未经用户明确许可,不得假设或使用默认值。
| 参数 | 必填 | 说明 | 默认值 |
|---|---|---|---|
| 是(表操作必填) | 实例endpoint URL | - |
| 是(表操作必填) | 实例名称 | - |
| 是(查询实例详情必填) | 实例名称 | - |
| 是(实例操作必填) | 区域ID(例如cn-hangzhou) | - |
| 是(表操作必填) | 数据表名称 | - |
注意: AccessKey凭证通过配置,不作为命令参数传递。aliyun configure
Authentication
身份认证
Pre-check: Alibaba Cloud Credentials RequiredSecurity Rules:
- NEVER echo or print AccessKey values
- NEVER ask the user to input AccessKey directly in plain text
- ONLY configure credentials using
aliyun configureIf no valid credentials exist:
- Obtain AccessKey from Alibaba Cloud Console
- For security, use RAM user credentials with
permissionAliyunOTSReadOnlyAccess- Configure credentials using Aliyun CLI
前置检查:必须提供阿里云凭证安全规则:
- 禁止回显或打印AccessKey值
- 禁止要求用户直接输入明文AccessKey
- 仅可通过
配置凭证aliyun configure如果不存在有效凭证:
- 从阿里云控制台获取AccessKey
- 出于安全考虑,使用拥有
权限的RAM用户凭证AliyunOTSReadOnlyAccess- 通过Aliyun CLI配置凭证
Configure Credentials (Aliyun CLI)
配置凭证(Aliyun CLI)
bash
undefinedbash
undefinedInteractive configuration (recommended)
交互式配置(推荐)
aliyun configure
aliyun configure
Follow prompts:
按照提示输入:
Aliyun Access Key ID [None]: <YOUR_ACCESS_KEY_ID>
Aliyun Access Key ID [None]: <YOUR_ACCESS_KEY_ID>
Aliyun Access Key Secret [None]: <YOUR_ACCESS_KEY_SECRET>
Aliyun Access Key Secret [None]: <YOUR_ACCESS_KEY_SECRET>
Default Region Id [None]: cn-hangzhou
Default Region Id [None]: cn-hangzhou
Default output format [json]: json
Default output format [json]: json
Default Language [zh]: en
Default Language [zh]: en
undefinedundefinedConfigure with Specific Profile
使用指定配置文件
bash
undefinedbash
undefinedCreate a named profile
创建命名配置文件
aliyun configure --profile tablestore-user
aliyun configure --profile tablestore-user
Use the profile for otsutil commands
执行otsutil命令时使用该配置文件
aliyun otsutil --profile tablestore-user list_instance -r cn-hangzhou
undefinedaliyun otsutil --profile tablestore-user list_instance -r cn-hangzhou
undefinedSupported Authentication Modes
支持的认证模式
| Mode | Description | Configure Command |
|---|---|---|
| AK | AccessKey ID/Secret (default) | |
| RamRoleArn | RAM role assumption | |
| EcsRamRole | ECS instance role | |
| OIDC | OIDC role assumption | |
| 模式 | 说明 | 配置命令 |
|---|---|---|
| AK | AccessKey ID/Secret(默认) | |
| RamRoleArn | RAM角色扮演 | |
| EcsRamRole | ECS实例角色 | |
| OIDC | OIDC角色扮演 | |
RAM Policy
RAM权限策略
Required permissions for Tablestore read-only operations:
json
{
"Version": "1",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ots:GetInstance",
"ots:ListInstance",
"ots:ListTable",
"ots:DescribeTable"
],
"Resource": "acs:ots:*:*:instance/*"
}
]
}Or use the managed policy:
AliyunOTSReadOnlyAccessSee references/ram-policies.md for detailed permissions.
Tablestore只读操作所需权限:
json
{
"Version": "1",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ots:GetInstance",
"ots:ListInstance",
"ots:ListTable",
"ots:DescribeTable"
],
"Resource": "acs:ots:*:*:instance/*"
}
]
}也可直接使用托管策略:
AliyunOTSReadOnlyAccess详细权限说明可参考references/ram-policies.md
Core Workflow
核心工作流
Part 1: Instance Read Operations
第一部分:实例读取操作
Task 1: Configure Instance (Connect to Instance)
任务1:配置实例(连接到实例)
Configure the endpoint to select which instance to operate on.
Important: You must configure the instance before performing any table operations.
Command Format:
bash
aliyun otsutil config --endpoint <endpoint> --instance <instanceName>Endpoint Format:
- Public:
https://<instance_name>.<region_id>.ots.aliyuncs.com - VPC:
https://<instance_name>.<region_id>.vpc.tablestore.aliyuncs.com
Example:
bash
aliyun otsutil config --endpoint https://myinstance.cn-hangzhou.ots.aliyuncs.com --instance myinstanceResponse:
json
{
"Endpoint": "https://myinstance.cn-hangzhou.ots.aliyuncs.com",
"AccessKeyId": "NTS**********************",
"AccessKeySecret": "7NR2****************************************",
"AccessKeySecretToken": "",
"Instance": "myinstance"
}配置endpoint以选择要操作的实例。
重要提示: 执行任何表操作前必须先配置实例。
命令格式:
bash
aliyun otsutil config --endpoint <endpoint> --instance <instanceName>Endpoint格式:
- 公网:
https://<instance_name>.<region_id>.ots.aliyuncs.com - VPC:
https://<instance_name>.<region_id>.vpc.tablestore.aliyuncs.com
示例:
bash
aliyun otsutil config --endpoint https://myinstance.cn-hangzhou.ots.aliyuncs.com --instance myinstance返回结果:
json
{
"Endpoint": "https://myinstance.cn-hangzhou.ots.aliyuncs.com",
"AccessKeyId": "NTS**********************",
"AccessKeySecret": "7NR2****************************************",
"AccessKeySecretToken": "",
"Instance": "myinstance"
}Task 2: Describe Instance
任务2:查询实例详情
View instance details including name, creation time, status, and quota.
Command Format:
bash
aliyun otsutil describe_instance -r <regionId> -n <instanceName>Example:
bash
aliyun otsutil describe_instance -r cn-hangzhou -n myinstanceResponse:
json
{
"ClusterType": "ssd",
"CreateTime": "2024-07-18 09:15:10",
"Description": "First instance created by CLI.",
"InstanceName": "myinstance",
"Network": "NORMAL",
"Quota": { "EntityQuota": 64 },
"ReadCapacity": 5000,
"Status": 1,
"TagInfos": {},
"UserId": "1379************",
"WriteCapacity": 5000
}Status Values: = Running. Other values indicate abnormal status.
1查看实例详情,包括名称、创建时间、状态、配额等信息。
命令格式:
bash
aliyun otsutil describe_instance -r <regionId> -n <instanceName>示例:
bash
aliyun otsutil describe_instance -r cn-hangzhou -n myinstance返回结果:
json
{
"ClusterType": "ssd",
"CreateTime": "2024-07-18 09:15:10",
"Description": "First instance created by CLI.",
"InstanceName": "myinstance",
"Network": "NORMAL",
"Quota": { "EntityQuota": 64 },
"ReadCapacity": 5000,
"Status": 1,
"TagInfos": {},
"UserId": "1379************",
"WriteCapacity": 5000
}状态值说明: = 运行中,其他值表示状态异常。
1Task 3: List Instances
任务3:列出实例列表
Get all instances in a specified region.
Command Format:
bash
aliyun otsutil list_instance -r <regionId>Example:
bash
aliyun otsutil list_instance -r cn-hangzhouResponse:
json
["myinstance", "another-instance"]Note: Returns empty arrayif no instances exist in the region.[]
获取指定区域下的所有实例。
命令格式:
bash
aliyun otsutil list_instance -r <regionId>示例:
bash
aliyun otsutil list_instance -r cn-hangzhou返回结果:
json
["myinstance", "another-instance"]注意: 如果该区域下没有实例,将返回空数组。[]
Part 2: Data Table Read Operations
第二部分:数据表读取操作
Prerequisite: You must first configure an instance endpoint using(Task 1) before running table operations.aliyun otsutil config
前置条件: 执行表操作前,必须先通过(任务1)配置实例endpoint。aliyun otsutil config
Task 4: Select Table (use
)
use任务4:选择数据表(use
)
useSelect a data table for subsequent operations.
Command Format:
bash
aliyun otsutil use --wc -t <tableName>| Parameter | Required | Description |
|---|---|---|
| No | Indicates the target is a data table (wide column) or index table |
| Yes | Table name |
Example:
bash
aliyun otsutil use -t mytable选择要执行后续操作的数据表。
命令格式:
bash
aliyun otsutil use --wc -t <tableName>| 参数 | 必填 | 说明 |
|---|---|---|
| 否 | 表示目标为数据表(宽列)或索引表 |
| 是 | 表名称 |
示例:
bash
aliyun otsutil use -t mytableTask 5: List Tables (list
)
list任务5:列出数据表(list
)
listList table names under the current instance.
Command Format:
bash
aliyun otsutil list [options]| Parameter | Required | Description |
|---|---|---|
| No | List all table names (data tables + timeseries tables) |
| No | List tables with detailed information |
| No | List only data table (wide column) names |
| No | List only timeseries table names |
Examples:
bash
undefined列出当前实例下的表名称。
命令格式:
bash
aliyun otsutil list [options]| 参数 | 必填 | 说明 |
|---|---|---|
| 否 | 列出所有表名称(数据表 + 时序表) |
| 否 | 列出表的详细信息 |
| 否 | 仅列出数据表(宽列)名称 |
| 否 | 仅列出时序表名称 |
示例:
bash
undefinedList tables of the current type
列出当前类型的表
aliyun otsutil list
aliyun otsutil list
List all tables
列出所有表
aliyun otsutil list -a
aliyun otsutil list -a
List only data tables
仅列出数据表
aliyun otsutil list -w
aliyun otsutil list -w
List only timeseries tables
仅列出时序表
aliyun otsutil list -t
undefinedaliyun otsutil list -t
undefinedTask 6: Describe Table (desc
)
desc任务6:查询表详情(desc
)
descView detailed table information including primary keys, TTL, max versions, and throughput.
Command Format:
bash
aliyun otsutil desc [-t <tableName>] [-f <format>] [-o <outputPath>]| Parameter | Required | Description |
|---|---|---|
| No | Table name. If omitted, describes the currently selected table (via |
| No | Output format: |
| No | Save output to a local JSON file |
Examples:
bash
undefined查看表的详细信息,包括主键、TTL、最大版本数、吞吐量等。
命令格式:
bash
aliyun otsutil desc [-t <tableName>] [-f <format>] [-o <outputPath>]| 参数 | 必填 | 说明 |
|---|---|---|
| 否 | 表名称。如果省略,将查询当前选中的表(通过 |
| 否 | 输出格式: |
| 否 | 将输出保存到本地JSON文件 |
示例:
bash
undefinedDescribe the currently selected table
查询当前选中的表详情
aliyun otsutil desc
aliyun otsutil desc
Describe a specific table
查询指定表的详情
aliyun otsutil desc -t mytable
aliyun otsutil desc -t mytable
Output in table format
以表格格式输出
aliyun otsutil desc -t mytable -f table
aliyun otsutil desc -t mytable -f table
Save table info to file
将表信息保存到文件
aliyun otsutil desc -t mytable -o /tmp/table_meta.json
**Example Response:**
```json
{
"Name": "mytable",
"Meta": {
"Pk": [
{ "C": "uid", "T": "string", "Opt": "none" },
{ "C": "pid", "T": "integer", "Opt": "none" }
]
},
"Option": {
"TTL": -1,
"Version": 1
},
"CU": {
"Read": 0,
"Write": 0
}
}Response Fields:
| Field | Description |
|---|---|
| Table name |
| Primary key columns: |
| Data time-to-live in seconds ( |
| Max attribute column versions retained |
| Reserved read/write capacity units |
aliyun otsutil desc -t mytable -o /tmp/table_meta.json
**返回示例:**
```json
{
"Name": "mytable",
"Meta": {
"Pk": [
{ "C": "uid", "T": "string", "Opt": "none" },
{ "C": "pid", "T": "integer", "Opt": "none" }
]
},
"Option": {
"TTL": -1,
"Version": 1
},
"CU": {
"Read": 0,
"Write": 0
}
}返回字段说明:
| 字段 | 说明 |
|---|---|
| 表名称 |
| 主键列: |
| 数据生命周期,单位为秒( |
| 保留的属性列最大版本数 |
| 预留读/写容量单元 |
Success Verification
成功验证
See references/verification-method.md for detailed verification steps.
Quick Verification:
- After : Response should show correct Endpoint and Instance
aliyun otsutil config - After : Verify expected instance names appear in the list
aliyun otsutil list_instance - After : Verify Status=1 (Running)
aliyun otsutil describe_instance - After : Verify expected table names appear
aliyun otsutil list - After : Verify table schema and configuration are correct
aliyun otsutil desc
详细验证步骤可参考references/verification-method.md
快速验证:
- 执行后:返回结果应显示正确的Endpoint和Instance
aliyun otsutil config - 执行后:验证预期的实例名称出现在列表中
aliyun otsutil list_instance - 执行后:验证Status=1(运行中)
aliyun otsutil describe_instance - 执行后:验证预期的表名称出现在列表中
aliyun otsutil list - 执行后:验证表结构和配置正确
aliyun otsutil desc
Related APIs
相关API
| CLI Command | Description |
|---|---|
| Configure CLI access (endpoint, instance) |
| Get instance details |
| List all instances in a region |
| Select a data table for subsequent operations |
| List tables under the current instance |
| View detailed table information |
See references/related-apis.md for complete API reference.
| CLI命令 | 说明 |
|---|---|
| 配置CLI访问信息(endpoint、实例) |
| 获取实例详情 |
| 列出某个区域下的所有实例 |
| 选择要执行后续操作的数据表 |
| 列出当前实例下的表 |
| 查看表的详细信息 |
完整API参考可查看references/related-apis.md
Best Practices
最佳实践
- Use RAM Users: Create RAM users with read-only permissions instead of using root account credentials
- Use ReadOnly Policy: Apply for query-only workflows
AliyunOTSReadOnlyAccess - Region Selection: Choose the region closest to your application for lower latency
- Network Type: Use VPC endpoint for better security in production environments
- Credential Security: Use for credential management; never hardcode credentials
aliyun configure - Use Profiles: Create dedicated profiles for different environments using
aliyun configure --profile <name> - Export Table Schema: Use to export and backup table definitions
aliyun otsutil desc -o <file>
- 使用RAM用户: 创建拥有只读权限的RAM用户,避免使用根账号凭证
- 使用只读策略: 针对仅查询的工作流,应用策略
AliyunOTSReadOnlyAccess - 区域选择: 选择离应用最近的区域,降低延迟
- 网络类型: 生产环境使用VPC endpoint,安全性更高
- 凭证安全: 使用管理凭证,永远不要硬编码凭证
aliyun configure - 使用配置文件: 通过为不同环境创建专用配置文件
aliyun configure --profile <name> - 导出表结构: 使用导出并备份表定义
aliyun otsutil desc -o <file>
Reference Links
参考链接
| Reference | Description |
|---|---|
| cli-installation-guide.md | Aliyun CLI installation guide |
| related-apis.md | Complete CLI command reference |
| verification-method.md | Verification steps for each operation |
| ram-policies.md | RAM permission requirements |
| Aliyun CLI GitHub | Aliyun CLI source code and documentation |
| Instance Operations Doc | Instance operations reference |
| Data Table Operations Doc | Data table operations reference |
| 参考文档 | 说明 |
|---|---|
| cli-installation-guide.md | Aliyun CLI安装指南 |
| related-apis.md | 完整CLI命令参考 |
| verification-method.md | 各操作的验证步骤 |
| ram-policies.md | RAM权限要求 |
| Aliyun CLI GitHub | Aliyun CLI源码和文档 |
| 实例操作文档 | 实例操作参考 |
| 数据表操作文档 | 数据表操作参考 |