kee
kee

Reputation: 11629

How to automate S3 http url permission grant

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

Answers (1)

300D7309EF17
300D7309EF17

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.

Bucket syntax:

s3client.put_bucket_acl(ACL='public-read', Bucket='bucketname')

Key syntax:

s3client.put_object_acl(ACL='public-read', Bucket='bucketname', Key='path/to/key')

Non-canned ACLs are a little easier in boto3.

Upvotes: 1

Related Questions