|
import os
ACCESS_KEY_ID = os.environ['ACCESS_KEY_ID']
SECRET_ACCESS_KEY = os.environ['SECRET_ACCESS_KEY']
import boto
def list_all_buckets(s3):
buckets = s3.get_all_buckets()
return buckets
# SNIP
def main():
s3 = boto.connect_s3(
host='s3-eu-west-1.amazonaws.com',
aws_access_key_id=ACCESS_KEY_ID,
aws_secret_access_key=SECRET_ACCESS_KEY)
buckets = list_all_buckets(s3)
# SNAP
for bucket in buckets:
print("First objects from bucket '{}' in location {}:".
format(bucket.name, bucket.get_location()))
for i, obj in enumerate(bucket.list()):
if i > 3:
break
print(" {}".format(repr(obj)))
main()
|