开发者

ec2 list my snapshots and owner id

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?


Try this

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

Something like this works for me to describe images.


https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-snapshots.html

If you specify one or more snapshot owners using the OwnerIds option, only snapshots from the specified owners and for which you have access are returned. The results can include the AWS account IDs of the specified owners, amazon for snapshots owned by Amazon, or self for snapshots that you own.

ec2.describeSnapshots(new DescribeSnapshotsRequest().withOwnerIds("self"));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜