You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用AWS CLI排除指定资源类型获取缺失标签的资源?

解决方法

由于aws resourcegroupstaggingapi get-resources的--resource-type-filters仅支持包含指定资源类型,无法直接实现反向排除,你可以通过扩展JMESPath查询语句,在筛选无CheckedTag标签的基础上,额外排除指定的资源类型。

直接使用以下命令即可满足需求:

aws resourcegroupstaggingapi get-resources --query 'ResourceTagMappingList[?Tags[?Key != `CheckedTag`] && ResourceType != `cloudwatch:alarm` && ResourceType != `ec2:instance`]'

命令说明

  • Tags[?Key != CheckedTag]:保留所有不包含CheckedTag标签的资源
  • ResourceType != cloudwatch:alarm&& ResourceType !=ec2:instance``:在上述结果中,进一步排除cloudwatch:alarm和ec2:instance类型的资源

如果你的账号下支持标签的资源类型很多,担心返回结果过大,也可以先通过--resource-type-filters指定需要关注的资源类型范围,再结合上述查询过滤,但仅排除少数类型时,直接用JMESPath过滤是最简便的方式。

内容的提问来源于stack exchange,提问作者ForeverLearner99999

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 03:12:08