Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CLI - S3 how to replace a folder atomically?

So,

Let's say I have a folder called /example in S3. This folder contains a file called a.txt.

using AWS CLI, how do I upload a local folder, also called example, and replace the current S3 /example atomically. The local folder contains a file called b.txt.

So, I want the behaviour to be that the new S3 /example folder only contains b.txt.

Basically, is there a way to atomically replace an entire folder in S3 with a new one via the AWS CLI?

Thank you!

like image 730
Karl Young Avatar asked Sep 15 '17 13:09

Karl Young


1 Answers

No, you can't do that.

For starters, S3 is an eventual consistent platform. That means that right after you do a write, you can still get old data back from S3. Practically, this converges quickly (seconds), but there is no upper bound. (They do provide consistency guarantees is some sequence of operations, but generally speaking, it's not strongly consistent)

Secondly, S3 does not have a concept of "folder" or "directory". S3 namespace is flat. The only thing that object /example/a.txt and /example/b.txt have in common is that they start with the same string, just like /foobar.txt and /foobaz.txt begin with the same string. (The User Interface does cheat a bit by treating the / character differently, and giving the illusion of directories)

like image 164
Niobos Avatar answered Oct 01 '22 07:10

Niobos