← 配置管理 | 使用指南(English) | 高级用法 →
CLI 的基本调用格式:
ve <service> <action> [--Param value ...] [---profile name] [---region region] [---endpoint endpoint]其中 --Param value 是 API 参数,---profile / ---region / ---endpoint 是 CLI 固定参数。
查看支持的服务:
ve --help查看某个服务下的接口:
ve ecs --help查看某个接口的参数:
ve ecs DescribeInstances --help查看版本:
ve version
ve -v无参数调用:
ve sts GetCallerIdentity带参数调用:
ve ecs DescribeInstances --InstanceIds.1 i-1234567890abcdef0多个参数:
ve rds_mysql ListDBInstanceIPLists --InstanceId mysql-xxxxxx --GroupName default参数名和值使用空格分隔。当前 CLI 参数语法是:
--Param value
---region cn-beijing不要写成 --Param=value 或 ---region=cn-beijing。
固定参数使用三横线 ---,不会和 API 的双横线参数冲突:
| 参数 | 作用 |
|---|---|
---profile |
本次调用使用指定 profile,不修改 current |
---region |
本次调用覆盖 region |
---endpoint |
本次调用覆盖 endpoint,并清空 endpoint resolver |
示例:
# 使用指定 profile
ve ecs DescribeInstances ---profile prod
# 使用指定 profile 并覆盖 region
ve ecs DescribeInstances ---profile prod ---region ap-southeast-1
# 只覆盖 region
ve ecs DescribeInstances ---region cn-shanghai
# 调用 STS 时临时指定 endpoint
ve sts GetCallerIdentity ---region cn-beijing ---endpoint sts.volcengineapi.com如果 ---profile 指向不存在的 profile,会直接报错。
对于 query/form 风格 API,参数值如果是 JSON object 或 JSON array,CLI 会尝试解析成 JSON:
ve rds_mysql ModifyDBInstanceIPList \
--InstanceId mysql-xxxxxx \
--GroupName default \
--IPList '["10.20.30.40","50.60.70.80"]'字符串类型参数会按字符串保留,不会因为内容看起来像 JSON 就强行解析。
对于 ContentType 为 application/json 的接口,可以直接传 --body:
ve rds_mysql ModifyDBInstanceIPList \
--body '{"InstanceId":"mysql-xxxxxx","GroupName":"default","IPList":["10.20.30.40","50.60.70.80"]}'--body 必须是 JSON object 或 JSON array。它不能和展开参数混用:
# 错误:--body 不能和其它 API 参数同时使用
ve rds_mysql ModifyDBInstanceIPList --body '{"InstanceId":"mysql-xxxxxx"}' --GroupName defaultapplication/json 接口也支持把参数展开为 dotted key,CLI 会根据 metadata 组装嵌套 JSON:
ve some_service SomeJsonAction \
--Name demo \
--Ports.1 80 \
--Ports.2 443 \
--Tags.1.Key env \
--Tags.1.Value prod数组下标从 1 开始,且必须连续。0、负数、跳号都会报错。
数组参数常见写法:
ve ecs DescribeInstances --InstanceIds.1 i-123 --InstanceIds.2 i-456对象数组写法:
ve some_service SomeAction \
--Filters.1.Key InstanceType \
--Filters.1.Values.1 ecs.g1.large \
--Filters.1.Values.2 ecs.g2.large对于 application/json 接口,CLI 会把上面的 dotted key 还原成嵌套对象和数组。对于非 JSON 接口,CLI 保持 dotted key 行为,由服务端/API 层处理。
CLI 允许未知 API 参数透传给服务端/API 层处理。除非参数路径本身不合法,CLI 不会仅因为 metadata 中没有某个参数就拦截。
示例:
ve ecs DescribeInstances --NewServerSideParam value这对服务端新增参数、metadata 尚未更新的场景有用。
使用默认 profile:
ve ecs DescribeInstances使用非默认 profile:
ve ecs DescribeInstances ---profile prod使用环境变量默认凭证链:
export VOLCENGINE_ACCESS_KEY=AK
export VOLCENGINE_SECRET_KEY=SK
export VOLCENGINE_REGION=cn-beijing
ve ecs DescribeInstances使用 OIDC profile:
ve configure set --profile ci-oidc --mode oidc --region cn-beijing \
--oidc-token-file /var/run/secrets/oidc-token \
--role-trn trn:iam::2100000000:role/CIRole
ve ecs DescribeInstances ---profile ci-oidc使用 ECS 实例角色 profile:
ve configure set --profile ecs-role --mode ecsrole --region cn-beijing --role-name MyRole
ve ecs DescribeInstances ---profile ecs-role缺少凭证时:
credentials not configured, please run 've login' or 've configure set', or set VOLCENGINE_ACCESS_KEY and VOLCENGINE_SECRET_KEY environment variables
缺少 region 时:
region not set, please set it via profile, ---region flag, or VOLCENGINE_REGION environment variable
固定参数不支持时:
---debug is not supported, supported fixed flags: ---profile, ---region, ---endpoint
当前支持的固定参数只有 ---profile、---region、---endpoint。