python - 列出我的 s3 中存在的每个存储桶中的对象
问题描述
我的 S3 中有 5 个存储桶。我必须通过 python 脚本为我的 s3 中存在的每个存储桶列出对象。我正在编写这样的脚本:
import boto3
def lambda_handler(event, context):
s3 = boto3.client('s3')
response = s3.list_buckets()
print('Existing buckets:')
for bucket in response['Buckets']:
for obj in bucket.object.all(['bucket']):
response = obj.get(
Key, StorageClass, Size)
print(response)
解决方案
您可以检查以下代码:
import boto3
s3 = boto3.client('s3')
s3r = boto3.resource('s3')
def lambda_handler(event, context):
response = s3.list_buckets()
for bucket_info in response['Buckets']:
bucket = s3r.Bucket(bucket_info['Name'])
print('Existing buckets:', bucket_info['Name'])
for object in bucket.objects.all():
print(' - ', object.key)
推荐阅读
- google-cloud-run - 端点开发者门户“试用此 API”和权限
- python - 如何比较熊猫,python中的列行
- javascript - next.config.json 中的多重导出
- reactjs - TabPanel:警告:validateDOMNesting(...):不能作为后代出现
- python - Matlab 的 pathtool 添加的 Python 等价物是什么?
- node.js - 树莓派节点服务器没有连接到其他机器
- checkstyle - 是否有强制类中的每个字段都有注释的检查样式规则?
- python - 添加事件回调到 kivy RecycleView
- c# - C# 为对象列表创建 Mock Configuration.GetSection(“Section:SubSection”)
- reactjs - 使用 validate 函数进行验证时出现 React Hook Form 问题