python - 上市后 S3 key 不立即出现

标签 python amazon-web-services amazon-s3 boto3

我正在使用 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')

虽然我得到了一个异常(exception),但当我去拿尸体时:

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 刚刚给了我 key ,但它说它不存在?

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

最佳答案

假设您使用的是“标准”端点是安全的。所有这些主要适用于它,而不是区域端点。 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已经看到了,我的轶事同意this statement超过 99% 的数据在 2 秒内存在。

您可以通过将端点从 s3.amazonaws.com 更改为 s3-external-1.amazonaws.com< 来启用写后读一致性,从而“修复”此问题:

s3client = boto3.client('s3', endpoint_url='s3-external-1.amazonaws.com')

关于python - 上市后 S3 key 不立即出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37403643/

相关文章:

Python3/Classes/OOP/如何使用方法更改对象自身的值?

image - 使用 AWS Amplify 从 React Native 上传到 S3

amazon-web-services - s3n ://处的主机名 URI 无效

amazon-web-services - 在 Lambda 中创建 AmazonS3Client 时出现 OutOfMemoryError

Java 通用事务管理

python - Cx_Oracle 使用 Pandas 数据帧输入更新数据库表

python - 如何有效地将缺失值的行添加到 pandas DataFrame 中?

python - 在 Python 模块分发中查找文件

python - AWS Lambda 错误消息 "Unable to import module ' lambda_function' : No module named 'lambda_function' ",

amazon-web-services - 在具有Coreos的AWS上使用kubernetes配置集群级别的日志记录