Is AWS S3 read guaranteed to return a newly create

2019-08-03 00:32发布

问题:

I've been reading the docs regarding read-after-write consistency with AWS S3 but I'm still unsure about this.

If I write an object to S3 and after getting a successful response from my write operation, I immediately attempt to read it, is the read operation guaranteed to return the object?

In other words, is it possible that the read operation will fail because it can't find the object? Because the read happened too soon after the write?

I'm only talking about new PUTs here, not updates to existing objects.

回答1:

Yes guaranteed to return the object (only for new objects) with one caveat:

As per AWS documentation:

Amazon S3 provides read-after-write consistency for PUTS of new objects in your S3 bucket in all regions with one caveat. The caveat is that if you make a HEAD or GET request to the key name (to find if the object exists) before creating the object, Amazon S3 provides eventual consistency for read-after-write.

Amazon S3 offers eventual consistency for overwrite PUTS and DELETES in all regions.

EDIT: credits to @Michael - sqlbot, more on HEAD (or) GET caveat:

If you send a GET or HEAD before the object exists, such as to check whether there's an object there before you upload, then the upload is not immediately consistent for read requests even after the upload is complete, because S3 has already made the only immediately consistent internal query it's going to make for that object, discovering, authoritatively, that there's no such key. The object creation becomes eventually consistent, since the creation has to "overwrite" the previous lookup that found nothing.

Based on following table provided in the link, "consistent reads" will never be stale.

Above provided link has nice example regarding how "read-after-write consistency" & "eventual consistency" works.

I would like to add this caution note to this answer to make things more clear:

Amazon S3 achieves high availability by replicating data across multiple servers within Amazon's data centers. If a PUT request is successful, your data is safely stored. However, information about the changes must replicate across Amazon S3, which can take some time, and so you might observe the following behaviors:

A process writes a new object to Amazon S3 and immediately lists keys within its bucket. Until the change is fully propagated, the object might not appear in the list.