3

Is there any way to specify to only include the latest version of each object in the ListVersionsRequest? I need the version value, so a simple AmazonS3Client.listObjects(...) will not suffice because S3ObjectSummary has no version information.

I am creating a utility that pings S3 for all objects in the versioned bucket and compares the latest version value to what the utility is already tracking. The only solution I can think of right now is just to do AmazonS3Client.listVersions(...), iterate through the S3VersionSummary list, handle the first most recent version then manually iterate and skip all older versions of an objet until it gets to the new key. Is this the best solution?

Thanks

hoobaka
  • 135
  • 1
  • 1
  • 9

3 Answers3

2

I only see two options:

  1. Do what you described and list all versions of the data that you have. Afterwards you'll get a list that is in order of versioning, so you'll need to know when to stop checking for versions. I think that this can be done by iterating through the list of versions and stopping at the first islatest() call that returns false ref

  2. You can list objects and then get the object summary for each object which will contain the version ID.

  • 1. I like the isLatest() method, I didn't see that myself, makes the code cleaner than manually checking when you get to the next key instead of just an older version of the same key. 2. The S3ObjectSummary object has no information regarding version, so I don't think listObjects(..) is a viable option. Using that, I would need to do a getObject(..) for each in the bucket to get the version from the metadata. – hoobaka Dec 14 '18 at 17:20
  • What I meant by "and then get the object summary for each object" was that you can get the list, and then for each item in the list call getObjectMetadata which will contain the versionID without fetching the object itself. Either way, the first solution is better if indeed the list of versions is returned that way. – Samuel Dominguez Dec 15 '18 at 00:58
0

The return from a listVersions as specified in the link to ListVersionsRequest indicates following...

and versions are sorted from the most recent to the least recent.

So ask for the versions of a specific s3 key and the first result in the list is the most recent version.

Michael Wiles
  • 20,902
  • 18
  • 71
  • 101
  • Correct, but this does not fit my use case because I do not want just a specific S3 key, I want all objects in the given bucket. – hoobaka Dec 14 '18 at 17:09
0

handle the first most recent version then manually iterate and skip all older versions of an objet until it gets to the new key

Instead of doing that, you can simple use isLatest(), available in S3VersionSummary