0
votes

I'm using the AWS CLI on my computer using the cygwin terminal, and I'm trying to output text of the query to describe the volumes my EC2 environement. The cli command works just fine, but the output text file to the tsv file results in a badly formatted document.

The aws cli command I'm using is:

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.

I'm trying to get the region/az on the same line as the instanceid and the volumeid but the outprint text seems to be representing this as a new line.

Is there any way possible to output text onto the same line using this cli command?

Thanks!

1

1 Answers

0
votes

The issue is that there is a 1-to-1 mapping between Volume and AZ, but a 1-to-many mapping between Volume and Attachment.

If you assume a single Attachment, then you can use:

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

This results in:

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