Created
September 16, 2016 09:37
-
-
Save seventhskye/f3f3a26026170519fc653a5ce4eafc9c to your computer and use it in GitHub Desktop.
A script to iterate through a bucket and change object acl's.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import boto3 | |
client = boto3.client('s3') | |
bucket = 'your-bucket' | |
prefix = 'a-path-in-s3' | |
NextContinuationToken = True | |
while NextContinuationToken: | |
if NextContinuationToken == True: | |
response = client.list_objects_v2(Bucket=bucket,Prefix=prefix) | |
else: | |
response = client.list_objects_v2(Bucket=bucket,Prefix=prefix,ContinuationToken=NextContinuationToken) | |
NextContinuationToken = response['NextContinuationToken'] | |
contents = response['Contents'] | |
for k in contents: | |
try: | |
client.put_object_acl(Bucket=bucket,Key=k['Key'],ACL='bucket-owner-full-control') | |
except: | |
print response['NextContinuationToken'] | |
print "Couldn't change permissions for key {}".format(k) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment