The program below gives read permission recursively to all the files present in an S3 bucket.


class ChangeBucketPermissions(object):
##Initializer
def __init__(self):
self.aws_access_key = "XXXXXXXX"
self.aws_secret_key = "XXXXXXXX"
aws_region = 'us-east-1'
self.s3_conn = boto.connect_s3(aws_access_key_id=self.aws_access_key,
aws_secret_access_key=self.aws_secret_key,
calling_format=boto.s3.connection.OrdinaryCallingFormat()))
self.all_users = 'http://acs.amazonaws.com/groups/global/AllUsers'
##This method changes the permission of all files in a bucket
def add_read_permissions(self, bucket_name):
try:
bucket = self.s3_conn.get_bucket(bucket_name)
for key in bucket:
readable = False
acl = key.get_acl()
for grant in acl.acl.grants:
if grant.permission == 'READ':
if grant.uri == self.all_users:
readable = True
if not readable:
key.make_public()
except Exception, e:
print "Exception occurred while changing all permissions : " + str(e)

Advertisement