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.

Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 App.

package org.doublecloud.awssample;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.PropertiesCredentials;
public class AwsEc2ListVolumes
  public static void main(String[] args) throws Exception
    AWSCredentials credentials = new PropertiesCredentials(AwsEc2ListVolumes.class.getResourceAsStream("/"));
    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,}
This entry was posted in Cloud Computing, Software Development and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.


  1. Posted April 4, 2016 at 6:37 am | Permalink

    nice Information ..
    Thanks for sharing…

  2. Posted April 13, 2016 at 7:40 am | Permalink

    Useful Information..
    Thanks for sharing..

  3. Posted April 14, 2016 at 6:39 am | Permalink

    Its a very helpful tutorial …

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


    My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.