Amazon S3 的 ListObjectsV2 是否在多个页面上自洽?

Is Amazon S3's ListObjectsV2 self-consistent over multiple pages?

ListObjectsV2 只能 return 1000 个结果,此时您必须返回另一页。

由于 Amazon S3 现在是高度一致的,并且在我列出其内容时存储桶可能会发生其他更新,第二页是否会从与第一页相同的时间点获得更多结果?还是要反映第二个页面被请求的那个时间点bucket的状态?

例如,如果我列出一个桶,获取第一页,删除本应出现在第二页的键,然后获取第二页,我是否仍会看到现在已删除的键?

的确,Amazon S3 现在 strongly consistent. This means once you upload an object, all people that read that object are guaranteed to get the updated version of the object. This does not meant that two different API calls are guaranteed to be in the same "state". Notably, for downloads, there is a situation where one download can get parts of two versions of the object if it's updated while being downloaded. More details are available in

至于你的问题,适用相同的基本规则:S3 从一次调用到下一次调用是高度一致的,一旦你对存储桶或对象进行了更改,any 调用更新后保证获得更新的数据。这意味着当您翻阅对象列表时,您将看到每个 API 调用获得最新状态时的变化:

import boto3

BUCKET='example-bucket'
PREFIX='so_question'

s3 = boto3.client('s3')

# Create a bunch of items
for i in range(3000):
    s3.put_object(Bucket=BUCKET, Key=f"{PREFIX}/obj_{i:04d}", Body=b'')

args = {'Bucket': BUCKET, 'Prefix': PREFIX + "/",}
result = s3.list_objects_v2(**args)
# This shows objects 0 to 999
print([x['Key'] for x in result['Contents']])

# Delete an object
s3.delete_object(Bucket=BUCKET, Key=f"{PREFIX}/obj_{1100:04d}")

# Request the next "page" of items
args['ContinuationToken'] = result['NextContinuationToken']
result = s3.list_objects_v2(**args)
# This will not show object 1100, showing objects 1000 to 2000
print([x['Key'] for x in result['Contents']])

这样做的好处是无法在一个 API 调用中获取存储桶中所有对象的列表(假设它有超过 1000 个项目):我不知道在任何时候获取存储桶的完整“快照”,当然,除非您可以确保在列出对象期间存储桶不会发生变化。