如何将文件锁定在AWS S3上?
通过锁定,我并不是说对象锁定S3可用。我说的是以下情况:
我有多个(python)流程,这些过程读写并写入S3上托管的单个文件;也许该文件是需要定期更新的各种索引。
这些过程并行运行,因此我要确保在给定时间只能写入一个过程(以避免伴随写入clobbering数据)。
如果我将其写入共享文件系统,我只能问使用flock
并将其用作同步对文件的访问的一种方式,但是我不能在S3 AFAICT上这样做。
在AWS S3上锁定文件的最简单方法是什么?
By locking, I don't mean the Object Lock S3 makes available. I'm talking about the following situation:
I have multiple (Python) processes that read and write to a single file hosted on S3; maybe the file is an index of sorts that needs to be updated periodically.
The processes run in parallel, so I want to make sure only a single process can ever write to the file at a given time (to avoid concomitant write clobbering data).
If I was writing this to a shared filesystem, I could just ask use flock
and use that as a way to sync access to the file, but I can't do that on S3 afaict.
What is the easiest way to lock files on AWS S3?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,AWS S3没有提供本机锁定对象的方式 - 如您指出的那样,没有
羊群
模拟。相反,您有一些选项:例如,使用数据库
,例如,Postgres提供咨询锁。设置此问题时,您将需要执行以下操作:
使用咨询锁时,您还需要考虑其他一些警告 - 从Postgres文档中:
请使用我看到的外部服务,
我看到人们使用了<<<<<<< a href =“ https://lockable.dev” rel =“ nofollow noreferrer”>可锁定解决此问题。来自他们的 docs ,他们似乎有一个python库:
$ pip安装可锁定-dev
如果您不使用Python,则可以通过击中一些HTTP端点来使用他们的服务:
Unfortunately, AWS S3 does not offer a native way of locking objects - there's no
flock
analogue, as you pointed out. Instead you have a few options:Use a database
For example, Postgres offers advisory locks. When setting this up, you will need to do the following:
There are a few other caveats you need to consider when using advisory locks - from the Postgres documentation:
Use an external service
I've seen people use something like lockable to solve this issue. From their docs, they seem to have a Python library:
$ pip install lockable-dev
If you're not using Python, you can still use their service by hitting some HTTP endpoints: