Garden Gnome
Garden Gnome

Reputation: 88

Retrieving all versions of an S3 Object

I'm looking to move from version 1 of the AWS SDK for Ruby to version 2. However I've hit a snag with S3 object versioning.

Given a reference to an S3 object in Version 1 of the API you could retrieve all versions of just that object: http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/S3Object.html#versions-instance_method

However Version 2 of the API does not seem to replicate this feature: http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Object.html

Am I missing something?

Upvotes: 1

Views: 1502

Answers (1)

Brad Buchanan
Brad Buchanan

Reputation: 1535

I think you're correct, and this feature is missing from the V2 API. I believe your only options are bucket.object_versions or client.list_object_versions.

You can retrieve all versions of an S3 object from the bucket like this:

# Retrieve Collection<ObjectVersion>
Aws::S3::Bucket.new('bucket-name')
  .object_versions(prefix: 'object-key')
  .reject { |version| version.key != 'object-key' }

I would guess that the Ruby SDK has made this change to better reflect the S3 REST API, where versions is its own subresource and objects don't have any knowledge of their own version history.

Upvotes: 1

Related Questions