Skip to content

Instantly share code, notes, and snippets.

@seventhskye
Created September 16, 2016 09:37
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 seventhskye/f3f3a26026170519fc653a5ce4eafc9c to your computer and use it in GitHub Desktop.
Save seventhskye/f3f3a26026170519fc653a5ce4eafc9c to your computer and use it in GitHub Desktop.
A script to iterate through a bucket and change object acl's.
#!/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