AWS CLI 按标签搜索资源
AWS CLI search resource by tags
我正在尝试使用 AWS CLI 按标签搜索资源。
我准备了这个 tag.json
文件:
{
"TagFilters": [ {
"Value": "postgres-dev",
"Key": "Name"
}
]
}
并使用此命令:
aws resourcegroupstaggingapi get-resources --tag-filters --cli-input-json file://tag.json
但是,它 returns 我的 AWS 账户中的每个资源(EC2、ELB 等)
,而不是仅返回具有此标签的数据库
谁能告诉我哪里做错了?
非常感谢。
你能用纯文本语法代替 JSON 试试吗?
aws resourcegroupstaggingapi get-resources --tag-filters "Key=Name,Values=postgres-dev"
对于多个过滤器(使用 AND):
aws resourcegroupstaggingapi get-resources \
--tag-filters "Key=Name,Values=postgres-dev" "Key=Test,Values=second"
另外,我认为应该是“Values”,而不是“Value”。
让我知道 ;)
使用 JSON 语法更新:
aws resourcegroupstaggingapi get-resources --cli-input-json file://tag.json
JSON正文:
{ "TagFilters": [ { "Key": "Name", "Values": [ "postgres-dev" ] } ] }
我正在尝试使用 AWS CLI 按标签搜索资源。
我准备了这个 tag.json
文件:
{ "TagFilters": [ { "Value": "postgres-dev", "Key": "Name" } ] }
并使用此命令:
aws resourcegroupstaggingapi get-resources --tag-filters --cli-input-json file://tag.json
但是,它 returns 我的 AWS 账户中的每个资源(EC2、ELB 等)
,而不是仅返回具有此标签的数据库谁能告诉我哪里做错了?
非常感谢。
你能用纯文本语法代替 JSON 试试吗?
aws resourcegroupstaggingapi get-resources --tag-filters "Key=Name,Values=postgres-dev"
对于多个过滤器(使用 AND):
aws resourcegroupstaggingapi get-resources \
--tag-filters "Key=Name,Values=postgres-dev" "Key=Test,Values=second"
另外,我认为应该是“Values”,而不是“Value”。
让我知道 ;)
使用 JSON 语法更新:
aws resourcegroupstaggingapi get-resources --cli-input-json file://tag.json
JSON正文:
{ "TagFilters": [ { "Key": "Name", "Values": [ "postgres-dev" ] } ] }