Home > Cloud Computing, Software Development > Amazon Web Service Java SDK Tutorial: List All Volumes

Amazon Web Service Java SDK Tutorial: List All Volumes

In my previous posts, I showed samples on how to create a new virtual machine instance, and how to list all the virtual machine instances you own. This sample shows how to list all the disk volumes that you have.

To run the following sample, you can check out the previous posts for the pom.xml file and how to get AWS credentials from AWS console.

Time to learn how to "Google" and manage your VMware and clouds in a fast and secure

package org.doublecloud.awssample;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.ec2.AmazonEC2;
import com.amazonaws.services.ec2.AmazonEC2Client;
import com.amazonaws.services.ec2.model.DescribeVolumesResult;
import com.amazonaws.services.ec2.model.Volume;
public class AwsEc2ListVolumes
  public static void main(String[] args) throws Exception
    AWSCredentials credentials = new PropertiesCredentials(AwsEc2ListVolumes.class.getResourceAsStream("/AwsCredentials.properties"));
    AmazonEC2 ec2 = new AmazonEC2Client(credentials);
    DescribeVolumesResult volReq = ec2.describeVolumes();
    int count = 1;
    for (Volume vol : volReq.getVolumes())
      System.out.println("Volume " + count   + "\n Details: " + vol);

The output will be something as follows:

Volume 1
 Details: {VolumeId: vol-72202aad,Size: 10,SnapshotId: snap-ba40cac8,AvailabilityZone: us-east-1d,State: in-use,CreateTime: Mon Feb 29 16:27:25 PST 2016,Attachments: [{VolumeId: vol-72202aad,InstanceId: i-ac61a42f,Device: /dev/sda1,State: attaching,AttachTime: Mon Feb 29 16:27:25 PST 2016,DeleteOnTermination: true}],Tags: [],VolumeType: gp2,Iops: 30,Encrypted: false,}
  1. April 4th, 2016 at 06:37 | #1

    nice Information ..
    Thanks for sharing…

  2. April 13th, 2016 at 07:40 | #2

    Useful Information..
    Thanks for sharing..

  3. April 14th, 2016 at 06:39 | #3

    Its a very helpful tutorial …

  1. No trackbacks yet.