Boto : Super easy Python library to interact with amazon web services
Nov 23rd, 2010 by harijay
I had first heard of Mitch Granaats boto thanks to “Monster Muck Mashup” where he used boto to build a video transcoding service using amazons compute and storage cloud EC2 and S3. Being a relative python newbie then, I remember reading the code examples and not understanding what they were doing entirely.
After a long period of dormancy I decided to resurrect and cleanup my S3 buckets. Stupid me! , I had turned on logging for the code-itch bucket ever so long ago. Result!,tens of thousands of log entries. Every S3 browser I tried, struggled to display and scroll the massive number of files. I needed a script and quick.
Initially I considered jets3t a java based super-library for all things AWS. But after reading an answer to this question on stackoverflow I decided to try boto again. This time around , I found the syntax very easy to comprehend. Within minutes I had a script that worked. The script read like pseudocode. I will reproduce it here.
I will definitely be delving more into boto to explore amazons many offerings.
Mitch Granaat also writes an excellent blog on all things aws and boto at elastician
Boto library home on googlecode
import boto
from boto import *
import re
# Regexp to match the log file names
log_key = re.compile("code-itch\.[\d]{4}\-[\d]{1,2}\-[\d]{1,2}\-[\d]{1,2}\-[\d]{1,2}\-[\d]{1,2}\-[a-fA-F\d]{16}")
f = open("listbuckets_code-itch_deleted.txt" , "w")
if __name__ == '__main__':
s3 = boto.connect_s3()
mybucket = s3.get_bucket("code-itch")
for key in mybucket:
if log_key.match(key.name):
f.write(key.name + "\n")
mybucket.delete_key(key.name)
print "Deleted",key.name
f.close()