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

如何通过AWS CLI列出指定EC2实例的卷及卷标签?

如何通过AWS CLI查询指定EC2实例对应的卷及其关联标签

步骤1:获取目标EC2实例关联的所有卷ID

先执行以下命令,通过实例ID过滤出挂载在该实例上的所有卷信息,从中提取卷ID(VolumeId字段):

aws ec2 describe-volumes --filters "Name=attachment.instance-id,Values=i-xxxxxx" --region us-east-2 --profile xxxxx

步骤2:查询指定卷的标签信息

拿到卷ID后,使用describe-tags命令查询对应卷的标签。注意:原示例中的过滤器参数有误,正确的应该用resource-id指定卷ID,命令如下:

aws ec2 describe-tags --filters "Name=resource-id,Values=vol-xxxxxx" --region us-east-2 --profile xxxxx --output=text

一步到位的合并查询

如果想直接输出实例关联卷的ID及对应标签,可借助JMESPath查询语法简化操作:

aws ec2 describe-volumes --filters "Name=attachment.instance-id,Values=i-xxxxxx" --region us-east-2 --profile xxxxx --query 'Volumes[*].{VolumeId: VolumeId, Tags: Tags}' --output=text

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 06:38:18