boto3 list_objects和list_objects_v2有什么区别? [英] What is the difference between boto3 list_objects and list_objects_v2?

查看:1617
本文介绍了boto3 list_objects和list_objects_v2有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to list objects in an Amazon s3 bucket in python using boto3.

似乎boto3有两个用于列出存储桶中对象的功能:list_objects()list_objects_v2().

It seems boto3 has 2 functions for listing the objects in a bucket: list_objects() and list_objects_v2().

两者之间有什么区别,并且使用一个相对于另一个有什么好处?

What is the difference between the 2 and what is the benefit of using one over the other?

推荐答案

并排比较.

list_objects():

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()

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个键的乘数,而无需处理最后一个键以获取下一页.

Added features. Due to the 1000 keys per page listing limits, using marker to list multiple pages can be an headache. Logically, you need to keep track the last key you successfully processed. With ContinuationToken, you don't need to know the last key, you just check existence of NextContinuationToken in the response. You can spawn parallel process to deal with multiply of 1000 keys without dealing with the last key to fetch next page.

这篇关于boto3 list_objects和list_objects_v2有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆