Reputation: 11629
I have a url (in the form of https://s3.amazonaws.com/...) pointing to a file in S3 and I want to have it downloadable by a user so I set the permission from S3 dashboard in AWS console but I learned that it is being reset whenever the file is re-written (the filename remains the same).
Is there a way to automatically set the permission right after the file creation? I looked at boto library but couldn't figure it out. Thanks in advance!
Upvotes: 0
Views: 420
Reputation: 24603
This is a very common operation.
With the Boto library, you can set an ACL. Assuming you have a Key:
key.set_acl('public-read')
If you don't have a Key, you'll need to have a Bucket:
bucket.set_acl('public-read', 'path/to/key')
You can use non-canned ACLs also. The documentation links through to that.
In boto3, you can also set an ACL.
s3client.put_bucket_acl(ACL='public-read', Bucket='bucketname')
s3client.put_object_acl(ACL='public-read', Bucket='bucketname', Key='path/to/key')
Non-canned ACLs are a little easier in boto3.
Upvotes: 1