AWS CLI describe volume attachment information

amazon ec2amazon-web-servicescommand-line-interface

In AWS CLI I am trying to get the ec2 volume "Attachment Information"

I see how I can find the Instance information, but this does not include the Attachment Information. The information I am looking for can actually be found in the ec2 Volume Management Console, but I want to use CLI to list it as text so I can put it in a text file. Is this possible.

aws ec2 describe-volumes --output text --region us-east-1 <– doesn't show the attachment information of the instance description.

http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-volumes.html

UPDATE: The above command does output the attachment information "i-1234567" but NOT the Instance Description. Example i-1234567 (AWSServer)

Best Answer

The attachment information is included in the describe-volumes function.

aws ec2 describe-volumes --output text --region us-east-1 includes a section called ATTACHMENTS (if attached), such as the following:

VOLUMES us-east-1a      2016-03-22T23:00:54.577Z        False   300     100    available        vol-12345678    gp2
TAGS    backup  yes
VOLUMES us-east-1d      2015-12-08T21:24:25.007Z        False   24      8      snap-12345678    in-use  vol-12345678    gp2
ATTACHMENTS     2015-12-08T21:24:25.000Z        True    /dev/xvda       i-12345678      attached        vol-12345678

The above example shows two volumes, one attached and one not attached.

The ATTACHMENTS section includes the date of attachment, the "Delete on Terminate" flag, device name, attached EC2 instance, and status.

Update:

In the AWS Console, the "Attachment Information" column displays the EC2 intance ID and the "Name" tag from the EC2 instance. The "Name" tag is not included in the results from describe-volumes.

To get the "Name" tag, you'll need to call aws ec2 describe-instances. Either a blanket call to get all EC2 instances, or by including the --instance-id parameter to get the EC2 instance you care about. The response from describe-instances includes the tags.

Related Topic