List all volumes attached to list of instances using aws cli

amazon-web-servicesaws-cli

I am using aws-cli and I need the list of all instance and the volumes associated with them.

instance-name,instance-id,volumes-associated

describe-instances and describe-volumes are different way to list instances and volumes. But I need a consolidated list as in the above format.
There could be multiple volumes associated with one instance.

Best Answer

This command will output:

  • The value associated with the 'Name' tag
  • Instance ID
  • EBS Volume ID

    aws ec2 describe-instances --query 'Reservations[*].Instances[*].[Tags[?Key==`Name`].Value,InstanceId,BlockDeviceMappings[*].Ebs.VolumeId]' --output text
    
    i-0d9c9b94b6583af4c
    Database
    vol-629feaa2
    i-3da61da2
    Web B
    vol-a6d443e7
    i-7d264642
    Web A
    vol-7840ce4a
    

There might be multiple EBS volumes associated with an instance.