描述卷 AWS CLI 命令

Describe-Volume AWS CLI command

我在我的计算机上使用 Cygwin 终端使用 AWS CLI,我正在尝试输出查询文本来描述我的 EC2 环境的卷。 cli 命令工作正常,但输出文本文件到 tsv 文件导致文档格式错误。

我使用的 aws cli 命令是:

aws ec2 describe-volumes --region $REGION --query 'Volumes[*].[Attachments[].{VolumeID:VolumeId,InstanceID:InstanceId},AvailabilityZone]' --output text >> Volumes_In_AWS.tsv

This is what the text file outprints onto the tsv file.

我试图让 region/az 与 instanceid 和 volumeid 在同一行,但输出文本似乎将其表示为新行。

有什么方法可以使用此 cli 命令将文本输出到同一行吗?

谢谢!

问题是 Volume 和 AZ 之间是一对一的映射,但是 Volume 和 Attachment 之间是一对多的映射。

如果你假设一个附件,那么你可以使用:

aws ec2 describe-volumes --query 'Volumes[*].[VolumeId, AvailabilityZone,Attachments[0].InstanceId]' --output text

这导致:

vol-387e4630    ap-southeast-2a i-0ef635853b22f705e
vol-6896efa2    ap-southeast-2b i-0c9c9b94b5583afdc