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

查看:50
本文介绍了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天全站免登陆