0 votes
1 view
in AWS by (18.1k points)

The IAM user can be referred to in policy documents by ${aws:username}.

If I call describeSnapshots() of AmazonEC2 Java interface I get a big number of snapshots as described in the documentation because it includes all visible snapshots.

However to get the list of my snapshots, should be easy with the API, but it isn't obvious to me. I tried to pass a DescribeSnapshotsRequests object to describeSnapshots()

DescribeSnapshotsRequest req = new DescribeSnapShotRequests();

List<String> ownerId = new ArrayList<String>();

ownerId.add("....");

req.setOwnerIds(ownerId);

DescribeSnapshotsResult res = ec2.describeSnapshots(req);

However, to get my user id, I printed the user id of all snapshots and manually identified mine, copied that user id, and used in the source code.

I hope there is a better way to list my snapshots, anyone knows?

1 Answer

0 votes
by (42.2k points)

Try this

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

This works for me to describe images.

...