上市后 S3 密钥不立即出现

S3 Key Not Present Immediatly After Listing

我正在使用 Python 和 boto3 与 S3 一起工作。

我正在列出一个 S3 存储桶并按前缀过滤:

bucket = s3.Bucket(config.S3_BUCKET)
for s3_object in bucket.objects.filter(Prefix="0000-00-00/", Delimiter="/"):

这给了我一个可迭代的 S3 对象。

如果我打印我看到的对象:

s3.ObjectSummary(bucket_name='validation', key=u'0000-00-00/1463665359.Vfc01I205aeM627249')

当我去拿尸体时,虽然我得到了一个例外:

content = s3_object.get()["Body"].read()

botocore.exceptions.ClientError: An error occurred (NoSuchKey) when calling the GetObject operation: The specified key does not exist.

所以 boto 刚刚给了我密钥,但它说它不存在?

并非所有键都会出现这种情况。一些。如果我在 AWS 控制台中搜索无效密钥,它不会找到它。

可以安全地假设您正在使用 'standard' 端点。所有这些主要适用于它,而不是区域端点。 S3 是原子的 eventually consistent. The documentation gives several examples,包括:

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.

偶尔会延迟 many hours have been seen, and my anecdata agrees with this statement 超过 99% 的数据存在于 2 秒内。

您可以通过将端点从 s3.amazonaws.com 更改为 s3-external-1.amazonaws.com:

来启用先写后读的一致性,"fixes"
s3client = boto3.client('s3', endpoint_url='s3-external-1.amazonaws.com')