Jay Caines-Gooby

Back in 5 mins

Versioning your Amazon S3 buckets

Wednesday February 10, 2010 @ 01:36 PM (GMT)

I’m sold hook line and sinker on the AWS platform. I’m especially impressed at the product innovation and ever-reducing prices.

A few days ago Amazon announced versioning for S3. This means that with the versioning flag for a bucket switched on, you can retrieve earlier versions of your files. Sweet.

Now, because I’m lazy, I tend to use S3Fox or Cyberduck for setting ACLs and creating european buckets and so on.

Neither of these have updated yet to support the versioning flag, and the AWS Console doesn’t have an S3 interface, so I thought I’d get my hands dirty and find out how to do it with the REST interface.

You issue a PUT to your bucket with the versioning querystring and the relevant XML:

<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <Status>Enabled</Status>
</VersioningConfiguration>

You can do it all with cURL, but the biggest pain is generating the correct Authorization: header to sign your API call.

Enter Tim Kay’s aws commandline tool – its a swiss knife for S3 and EC2 calls. Enabling the versioning was as simple as:

aws put my.bucket.com?versioning versioning.xml

Where versioning.xml contains the VersioningConfiguration xml snippet listed above.

To check the versioning status of a bucket, you do:

aws get my.bucket.com?versioning

Before you run the aws commandline, you’ll need to create an ~/.awssecret file with your AWS key and secret key. Don’t forget to chmod 600.

Comments

Hey, that’s a great stuff. But I wonder if I could enable versioning for already existing objects inside versioning-enabled bucket. Do anybody know, how could it be achieved?

Gravatar icon
Toli
Wednesday February 24, 2010 @ 04:32 PM (GMT)

Thanks for the write-up. Worked like a charm. Not sure about ‘Toli’ comment – worked for existing buckets for me.

Gravatar icon
Thursday March 04, 2010 @ 10:50 AM (GMT)

I think you skipped over some really important info here — currently Tim Kay’s aws script doesn’t support s3 versioning, so first you need to modify the script to support versioning like Miguel Landaeta has. If you don’t use a modified script, putting to ?versioning doesn’t turn on versioning — it simply creates a new item named ?versioning in your bucket.

Gravatar icon
Friday July 30, 2010 @ 07:34 PM (BST)
New comment

required, won't be displayed

optional

Don't type anything here unless you're an evil robot:


And especially don't type anything here:

Basic XHTML (including links) is allowed, just don't try anything fishy. Your comment will be auto-formatted unless you use your own <p> tags for formatting. You're also welcome to use Textile.

Copyright © 2011 Jay Caines-Gooby. All rights reserved.
Powered by Thoth.