Created
April 27, 2017 17:23
-
-
Save mda590/50e07e376b92fdd8d014c1bce69d525d to your computer and use it in GitHub Desktop.
List all S3 Buckets and Objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Print all S3 buckets and objects | |
# Warning: If you have a lot of S3 objects, this could potentially incur a large cost. | |
# | |
import boto3 | |
client = boto3.client('s3') | |
buckets = client.list_buckets() | |
for bucket in buckets["Buckets"]: | |
print(bucket['Name']) | |
keylist = client.list_objects_v2(Bucket=bucket["Name"], Delimiter='/') | |
if "Contents" in keylist: | |
for object in keylist.get('CommonPrefixes'): | |
print(object.get('Prefix')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment