简体   繁体   English

AWS CLI - S3 如何以原子方式替换文件夹?

[英]AWS CLI - S3 how to replace a folder atomically?

So,所以,

Let's say I have a folder called /example in S3.假设我在 S3 中有一个名为/example的文件夹。 This folder contains a file called a.txt .该文件夹包含一个名为a.txt的文件。

using AWS CLI, how do I upload a local folder, also called example , and replace the current S3 /example atomically.使用 AWS CLI,如何上传本地文件夹(也称为example )并自动替换当前的 S3 /example The local folder contains a file called b.txt .本地文件夹包含一个名为b.txt的文件。

So, I want the behaviour to be that the new S3 /example folder only contains b.txt .所以,我希望行为是新的 S3 /example文件夹只包含b.txt

Basically, is there a way to atomically replace an entire folder in S3 with a new one via the AWS CLI?基本上,有没有办法通过 AWS CLI 用新文件夹原子地替换 S3 中的整个文件夹?

Thank you!谢谢!

No, you can't do that.不,你不能那样做。

For starters, S3 is an eventual consistent platform.首先,S3 是一个最终一致的平台。 That means that right after you do a write, you can still get old data back from S3.这意味着在您写入之后,您仍然可以从 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没有“文件夹”或“目录”的概念。 S3 namespace is flat. S3 命名空间是扁平的。 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.对象/example/a.txt/example/b.txt唯一的共同点是它们以相同的字符串开头,就像/foobar.txt/foobaz.txt以相同的字符串开头一样。 (The User Interface does cheat a bit by treating the / character differently, and giving the illusion of directories) (用户界面通过不同地对待/字符并给人以目录的错觉而作弊)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM