使用 boto3 列出存储桶的内容 [英] Listing contents of a bucket with boto3

查看:27
本文介绍了使用 boto3 列出存储桶的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 boto3 查看 S3 中存储桶内的内容?(即做一个 "ls")?

How can I see what's inside a bucket in S3 with boto3? (i.e. do an "ls")?

执行以下操作:

import boto3
s3 = boto3.resource('s3')
my_bucket = s3.Bucket('some/path/')

返回:

s3.Bucket(name='some/path/')

我如何查看其内容?

推荐答案

查看内容的一种方式是:

One way to see the contents would be:

for my_bucket_object in my_bucket.objects.all():
    print(my_bucket_object)

这篇关于使用 boto3 列出存储桶的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆