Skip to content

Instantly share code, notes, and snippets.

@gwax
Created February 9, 2016 19:56
Show Gist options
  • Save gwax/052081a473b54d33fd39 to your computer and use it in GitHub Desktop.
Save gwax/052081a473b54d33fd39 to your computer and use it in GitHub Desktop.
Find everything on s3
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