擅长:python、mysql、java
<p>这类似于“ls”,但它不考虑前缀文件夹约定,并将列出bucket中的对象。它留给读者过滤掉作为键名一部分的前缀。</p>
<p>在Python 2中:</p>
<pre><code>from boto.s3.connection import S3Connection
conn = S3Connection() # assumes boto.cfg setup
bucket = conn.get_bucket('bucket_name')
for obj in bucket.get_all_keys():
print(obj.key)
</code></pre>
<p>在Python 3中:</p>
<pre><code>from boto3 import client
conn = client('s3') # again assumes boto.cfg setup, assume AWS S3
for key in conn.list_objects(Bucket='bucket_name')['Contents']:
print(key['Key'])
</code></pre>