Aaron McMillin
Aaron McMillin

Reputation: 2667

Can I use versioning in s3 to ensure that I am PUTing over the latest version of a document?

Consider the the use case where I GET a document from s3, makes some changes then PUT the document. Since that operation isn't atomic, I'd like to ensure that when I PUT the document the version I started with was still current.

So basically when I do the PUT I want to provide the versionid of the document I started with, and get 409 conflict error if that version is no longer the current version.

I'm really hoping s3 supports this, but I've not been able to find an example yet.

Upvotes: 0

Views: 204

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179124

There is no mechanism for this sort of conditional PUT in S3.

Overwrite PUTs are only eventually consistent, so the notion of what was the current version when a PUT occurred is not something that has a strict meaning in S3.

You could come close by sending a HEAD request immediately before the PUT to verify that the version you're working on still appears to be the current version, and in doing so, avoid an obvious condition where the object has been overwritten an become consistent between when you fetched it and when you are about to overwrite it, but there's an inevitable window of time, however short it may be, when the object still could be or could have extremely recently been changed.

You could also maybe mitigate the potential harm by adding metadata to the replacement copy, such as x-amz-meta-replaces-version-id and the former versionId, auditing it later or in near real time with an S3 event notification, and catching cases where an intermediate version was uploaded... but there's no conditional update capability or object locking built-in.

Upvotes: 3

Related Questions