【问题标题】:List all objects in AWS S3 bucket with their storage class using Boto3 Python使用 Boto3 Python 列出 AWS S3 存储桶中的所有对象及其存储类
【发布时间】:2021-05-09 13:32:03
【问题描述】:

我有一个要求,我需要列出 s3 存储桶中的所有对象及其存储类。

如何使用Python 和Boto3 实现这一目标?我使用Python 3.7。

【问题讨论】:

标签: python-3.x amazon-web-services amazon-s3 boto3


【解决方案1】:

此代码将列出给定存储桶中的所有对象,显示对象名称(键)和存储类。此代码使用访问 Amazon S3 的 resource 方法。

import boto3

s3_resource = boto3.resource('s3')

bucket = s3_resource.Bucket('my-bucket')

for object in bucket.objects.all():
    print(object.key, object.storage_class)

【讨论】:

    【解决方案2】:

    帮自己一个忙,使用S3 Inventory Report。

    Amazon S3 清单是 Amazon S3 提供的帮助工具之一 管理您的存储。您还可以简化和加快业务 使用 Amazon S3 清单的工作流和大数据作业,它提供 Amazon S3 同步列表 API 的计划替代方案 操作。

    报告中列出的项目之一是:

    • 存储类 - 用于存储对象的存储类

    Here's the full list of what's in the report.

    最后,你可以使用S3 Inventory REST API。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-28
      • 2015-10-23
      • 2021-11-25
      • 2011-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多