def TestMain(cfg):
# boto3.set_stream_logger(name='botocore')
# os.environ["HTTP_PROXY"] = "http://localhost:8080"
# os.environ["HTTPS_PROXY"] = "https://localhost:8999"
sess = boto3.session.Session(
aws_access_key_id = cfg['access_key_id'],
aws_secret_access_key = cfg['access_key'],
region_name = cfg['region']
)
s3 = sess.resource('s3')
print '\n--- List Buckets ---'
for bucket in s3.buckets.all():
print bucket.name
bkt = s3.Bucket('fred4')
# print '\n--- Key exists ---'
# print bkt.get_key('zuxisaki') # i dont think this works
print '\n--- List objects in bucket fred4 ---'
# len(list(bkt.objects.filter(Prefix='index'))) # One request, doesnt return tons of data!
for i,obj in enumerate(bkt.objects.all()): # 1348 items - 2 requests, and boto does it for me.
print i, obj.key, obj.size # does not fetch the actual object, score
if i > 10000: break
print '\n--- Body reads ---'
print obj.get()['Body'].read() # from iteration
print bkt.Object('zuxisaki').get()['Body'].read() # by name
print '\n--- Body write ---'
data = 'A'*128
nm = RandChars(8)
bkt.Object(nm).put(Body=data)
print 'Wrote key=',nm
# Is Best rand chars