Created
April 30, 2013 01:42
-
-
Save tristanwietsma/5486126 to your computer and use it in GitHub Desktop.
AWS S3 administration scripts Some administration scripts for Amazon Web Services' S3 using Boto.
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 os, sys | |
from boto.s3.connection import S3Connection | |
from boto.s3.bucket import Bucket | |
AWS_ACCESS_KEY = os.getenv('AWS_ACCESS_KEY') | |
AWS_SECRET_KEY = os.getenv('AWS_SECRET_KEY') | |
conn = S3Connection(AWS_ACCESS_KEY, AWS_SECRET_KEY) | |
bucket_name = sys.argv[1] | |
bucket = Bucket(conn, bucket_name) | |
for i in bucket.list(): | |
print 'deleting...', i | |
bucket.delete_key(i.key) |
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
from __future__ import division | |
import os | |
from boto.s3.connection import S3Connection | |
AWS_ACCESS_KEY = os.getenv('AWS_ACCESS_KEY') | |
AWS_SECRET_KEY = os.getenv('AWS_SECRET_KEY') | |
conn = S3Connection(AWS_ACCESS_KEY, AWS_SECRET_KEY) | |
buckets = conn.get_all_buckets() | |
print 'Bucket'.ljust(30), | |
print 'Items'.ljust(15), | |
print 'Kb'.ljust(15) | |
for bucket in buckets: | |
sz = 0 | |
num = 0 | |
for i in bucket.list(): | |
num += 1 | |
sz += i.size/1024. | |
print ('%s'%bucket.name).ljust(30), | |
print ('%s'%num).ljust(15), | |
print ('%.0f'%sz).ljust(15) | |
for i in bucket.list(): | |
print '\t', i.key |
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 os, sys | |
from boto.s3.connection import S3Connection | |
from boto.s3.bucket import Bucket | |
from boto.s3.key import Key | |
AWS_ACCESS_KEY = os.getenv('AWS_ACCESS_KEY') | |
AWS_SECRET_KEY = os.getenv('AWS_SECRET_KEY') | |
conn = S3Connection(AWS_ACCESS_KEY, AWS_SECRET_KEY) | |
bucket_name = sys.argv[1] | |
bucket = Bucket(conn, bucket_name) | |
k = Key(bucket) | |
k.key = sys.argv[2] | |
k.set_contents_from_filename(sys.argv[3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment