关于对S3-bucket-桶list_objects与list_objects_v2的区别
Posted on 2023-04-07 21:19 520_1351 阅读(1030) 评论(0) 编辑 收藏 举报在AWS SDK for Python (Boto3) 文档上可以看到S3的client的部分,有list_objects 与 list_objects_v2 两个操作
根据名字看来就可以猜到是列出s3 bucket中的对象,其中V2应该是后面出来的版本吧,于是认真看了一下介绍
S3.Client.list_objects(**kwargs)
Returns some or all (up to 1,000) of the objects in a bucket. You can use the request parameters as selection criteria to return a subset of the objects in a bucket. A 200 OK response can contain valid or invalid XML. Be sure to design your application to parse the contents of the response and handle it appropriately.
Warning
This action has been revised. We recommend that you use the newer version, ListObjectsV2, when developing applications.
For backward compatibility, Amazon S3 continues to support ListObjects
.
S3.Client.list_objects_v2(**kwargs)
Returns some or all (up to 1,000) of the objects in a bucket with each request. You can use the request parameters as selection criteria to return a subset of the objects in a bucket. A 200 OK
response can contain valid or invalid XML. Make sure to design your application to parse the contents of the response and handle it appropriately. Objects are returned sorted in an ascending order of the respective key names in the list. For more information about listing objects, see Listing object keys programmatically
To use this operation, you must have READ access to the bucket.
To use this action in an Identity and Access Management (IAM) policy, you must have permissions to perform the s3:ListBucket
action. The bucket owner has this permission by default and can grant this permission to others. For more information about permissions, see Permissions Related to Bucket Subresource Operations and Managing Access Permissions to Your Amazon S3 Resources.
Warning
This section describes the latest revision of this action. We recommend that you use this revised API for application development. For backward compatibility, Amazon S3 continues to support the prior version of this API, ListObjects.
也即 list_objects_v2 是最新修订版本。官方建议是使用此修订后的API进行应用程序开发。为了向后兼容性,AmazonS3继续支持此API的早期版本ListObjects
因此目前如果需要列出对象的基础信息,肯定是建议使用 list_objects_v2 的,可以返回如下几个字段的
Key, LastModified, ETag, Size, StorageClass , 输出后将数据清洗后的样式如下:
尊重别人的劳动成果 转载请务必注明出处: https://www.cnblogs.com/5201351/p/17297407.html
作者:一名卑微的IT民工
出处:https://www.cnblogs.com/5201351
本博客所有文章仅用于学习、研究和交流目的,欢迎非商业性质转载。
由于博主的水平不高,文章没有高度、深度和广度,只是凑字数,不足和错误之处在所难免,希望大家能够批评指出。
博主是利用读书、参考、引用、复制和粘贴等多种方式打造成自己的文章,请原谅博主成为一个卑微的IT民工!