Amazon S3 Aws - Change an object's acl using boto API

This code shows how to change the access rights on a file uploaded on S3 storage.     
This example sets the object foo_bar.txt to be publicly readable, and secret.txt to be private.

Supported acl values defined in

CannedACLStrings = ['private', 'public-read', 'project-private', 'public-read-write', 'authenticated-read', 'bucket-owner-read', 'bucket-owner-full-control']

Learn more about CannedACLStrings: [](
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
# Public ACL example # Here you get the key reference for file foo_bar.txt foo_bar_key = bucket.get_key('foo_bar.txt') # This set the foo_bar file publicly readable foo_bar_key.set_canned_acl('public-read') # Private ACL example # Here you get the key reference for file secret.txt secret_key = bucket.get_key('secret.txt') # This set the secret.txt file as private secret_key.set_canned_acl('private')
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus