javaamazon-web-servicesamazon-ec2aws-storage-gateway

Cannot retrieve Storage Gateway snapshots using Java API


I'm trying to grab a list of snapshots from our Storage Gateway and put them into a JTable. However, when I use the AWS Java API to retrieve a list of snapshots, I only am able to retrieve what appears to be the public snapshots published by Amazon. When I set the DescribeSnapshotsRequest.setOwnerIds() to include "self", the list is empty.

Here is the offending code:

private void createTable() {
        Object[][] data = null;
        String[] columns = new String[]{"Snapshot ID", "Owner ID", "Snapshot Date"};

        DescribeSnapshotsRequest req = new DescribeSnapshotsRequest();
        req.setOwnerIds(Arrays.<String>asList("self"));

        try {
            snapshots = ec2Client.describeSnapshots(req).getSnapshots();

            data = new Object[snapshots.size()][3];

            int i = 0;
            for(Snapshot item : snapshots) {
                data[i][0] = item.getSnapshotId();
                data[i][1] = item.getOwnerId();
                data[i][2] = item.getStartTime();
                i++;
            }
        } catch(Exception e) {
            System.out.println("Invalid Credentials!");
        }

        table = new JTable(data, columns);
        table.setAutoCreateRowSorter(true);
    }

The List snapshots is empty unless I either remove the DescribeSnapshotsRequest, or set the owner ID to "amazon".

Long story short, why can't I access my private snapshots from the Storage Gateway?


Solution

  • Figured it out. Turns out you have to explicitly define the EC2 endpoint. Somehow I missed that step.

    Here is the list of endpoints: http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region

    AmazonEC2Client.setEndpoint("<Endpoint URL>");