如何通过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
相关产品推荐
相关产品推荐

