Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
616 views
in Technique[技术] by (71.8m points)

python - What is the difference between boto3 list_objects and list_objects_v2?

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Comparison side by side.

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...