Created
February 9, 2016 19:56
-
-
Save gwax/052081a473b54d33fd39 to your computer and use it in GitHub Desktop.
Find everything on s3
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
import csv | |
import boto3 | |
s3 = boto3.resource('s3') | |
with open('s3_catalog.csv', 'w') as csvfile: | |
csvwriter = csv.writer(csvfile) | |
for s3_bucket in s3.buckets.all(): | |
print(s3_bucket.name) | |
try: | |
for s3_obj in s3_bucket.objects.all(): | |
csvwriter.writerow([s3_bucket.name, s3_obj.key]) | |
except Exception as e: | |
csvwriter.writerow([s3_bucket.name, 'ERROR: {}'.format(e)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment