On AWS portal , we see Volume IDs of EBS volumes. However on EC2 Machine, we see disk names. Sometimes, we need to know which disk name is associated with which volume ID. In this article, we will talk how to find drive letters from EBS volume IDs.
Before we start, Please go through article to configure AWS CLI which is prerequisite to run related commands.
aws ec2 describe-volumes
command is used to retrieve information about Amazon Elastic Block Store (EBS) volumes in your AWS account. Please refer official AWS documentation to know about various parameters and filters that could passed to list various EBS related information.
1 : List all EBS volumes in the current AWS region
1. Here is an example of how to use the aws ec2 describe-volumes
command:
aws ec2 describe-volumes
When you run this command, the output will contain information about all EBS volumes in the current AWS region, including the volume ID, size, state, availability zone, and more. Output would be in default format specified while configuring AWS CLI
2 : list information for all volumes in a specific region and specific output format:
You can use the --region
and --output
options with the describe-volumes
command in the AWS CLI to retrieve information about Amazon EBS volumes in a specific region and output the result in a specific format.
Here’s an example command to list information for all volumes in the us-west-2
region and output the result in a tabular format:
aws ec2 describe-volumes --region us-west-2 --output table
This command retrieves information for all volumes in the us-west-2
region and outputs the result in a tabular format. You can also use other output formats such as json
, text
, yaml
, etc. by specifying the appropriate value for the --output
option.
Note that you may need to replace us-west-2
with the name of the region you want to retrieve information for.
3 : list information for all volumes attached to an EC2 instance in table format:
aws ec2 describe-volumes --filters Name=attachment.instance-id,Values=<instance-id> --query 'Volumes[*].{ID:VolumeId,State:State,Size:Size,Device:Attachments[*].Device}' --output table
This command lists the VolumeId
, State
, Size
, and Device
(drive letter) information for each volume attached to the specified EC2 instance in a tabular format. The --filters
parameter specifies a filter to retrieve only volumes attached to the specified instance. The --query
parameter uses a JMESPath query to retrieve the desired attributes for each volume. The --output
parameter specifies the output format as a table.
4 : Command to retrieve the drive letter associated with a specific volume ID:
aws ec2 describe-volumes --volume-ids vol-0123456789abcdef --query 'Volumes[0].Attachments[*].Device' --output text
In this command, replace vol-0123456789abcdef
with the volume ID you want to check.
Based on requirement, this command can be used to provide output.
Happy Learning !