Search code examples
javaamazon-s3aws-java-sdk

AWS S3 Java SDK - ListVersionsRequest Get Only Latest Versions


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


Solution

  • 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.