Skip to content

Instantly share code, notes, and snippets.

@amalgjose
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalgjose/e4a9cbfda9a5a51c7a2b to your computer and use it in GitHub Desktop.
Save amalgjose/e4a9cbfda9a5a51c7a2b to your computer and use it in GitHub Desktop.
This code is for changing the permission of all the files in an amazon S3 bucket. This program will add read permissions to all the files present in the specified 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment