I have a bucket with 10^6 keys in it. I want to make all objects in it private.
I tried s3cmd which fails after sometime. I tried it with boto3, but it is painfully slow.
import boto3
boto3.setup_default_session(aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key)
s3_client = boto3.client('s3')
s3_resource = boto3.resource('s3')
bucket = s3_resource.Bucket(bucket_name)
bucket_acl = bucket.Acl()
i = 0
for object_summary in bucket.objects.all():
i += 1
object_acl = object_summary.Acl()
if i % 100 == 1:
print('{} {}'.format(i, object_summary.key))
object_acl.put(ACL='private')
Is there any way to do batch operation or do everything private by setting some bucket policy.
Any other suggestion is also welcome.
Unfortunately i did not find a good solution. I decided to run it for 70 hours with nohup in background.
A possible solution I thought was to split keys in bucket into multiple sets and run them using multiple threads.
But in the end I just waited 70 hours.
You don't need to do anything. Objects in Amazon S3 are private by default.
Things that make them public are: