boto3 list_objects 和 list_objects_v2 有什么区别?

What is the difference between boto3 list_objects and list_objects_v2?

我正在尝试使用 boto3 列出 python 中 Amazon s3 存储桶中的对象。

似乎 boto3 有 2 个函数用于列出存储桶中的对象:list_objects()list_objects_v2()

2 之间有什么区别,使用一个比另一个有什么好处?

并排比较。

list_objects() :

response = client.list_objects(
    Bucket='string',
    Delimiter='string',
    EncodingType='url',
    #Marker to list continuous page
    Marker='string',
    MaxKeys=123,
    Prefix='string'
)

list_objects_v2()

response = client.list_objects_v2(
    Bucket='string',
    Delimiter='string',
    EncodingType='url',
    MaxKeys=123,
    Prefix='string',
    # Replace marker to list continuous page
    ContinuationToken='string',

    # set to True to fetch key owner info. Default is False.
    FetchOwner=True|False,

    # This is similar to the Marker in list_object()
    StartAfter='string'
)

新增功能。由于每页列出 1000 个键的限制,使用标记列出多个页面可能会让人头疼。从逻辑上讲,您需要跟踪您成功处理的最后一个密钥。使用 ContinuationToken,您不需要知道最后一个密钥,只需检查响应中是否存在 NextContinuationToken。您可以生成并行进程来处理 1000 个键的乘积,而无需处理最后一个键来获取下一页。