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

如何从AWS SSM清单中移除已终止的实例?

移除AWS SSM清单中已终止的托管节点条目

手动单实例删除

使用AWS CLI的delete-inventory命令,直接指定已终止实例的ID和对应库存类型即可删除条目:

aws ssm delete-inventory --instance-id "i-0ffeeb0756265c10f" --type-name "AWS:InstanceInformation"

批量清理已终止实例条目

如果存在大量已终止实例需要处理,可以结合CLI和文本处理工具批量操作:

  1. 先导出所有状态为Terminated的实例ID到本地文件:
aws ssm get-inventory --query 'Entities[?Data.AWS:InstanceInformation.Content[0].InstanceStatus==`Terminated`].Id' --output text | tr '\t' '\n' > terminated-instances.txt
  1. 循环读取文件中的实例ID,执行删除命令:
while read instance_id; do
  aws ssm delete-inventory --instance-id "$instance_id" --type-name "AWS:InstanceInformation"
done < terminated-instances.txt

补充说明

  • 执行操作的IAM身份需要具备ssm:DeleteInventory权限
  • AWS默认会在实例终止后的30天左右自动清理这类库存条目,若无需立即清理,可等待系统自动处理
  • 已终止实例不会显示在控制台的托管节点列表中,属于正常逻辑,仅库存数据会临时保留一段时间

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 08:45:48