Make a file in s3 public using python and boto

UserX picture UserX · Apr 2, 2015 · Viewed 11.8k times · Source

I have thins link below, and when I try to acess it it appears an xml file saying "Acess denied".

And I need to go to aws managment console and make this part-0000 file public so I can acess it.

Do you know how can I give permissions using boto with python so I can acess this link without needed to go to aws managmet console and make the file public?

downloadLink = 'https://s3.amazonaws.com/myFolder/uploadedfiles/2015423/part-00000'

Answer

garnaat picture garnaat · Apr 5, 2015

This should give you an idea:

import boto.s3
conn = boto.s3.connect_to_region('us-east-1')  # or region of choice
bucket = conn.get_bucket('myFolder')
key = bucket.lookup('uploadedfiles/2015423/part-00000')
key.set_acl('public-read')

In this case, public-read is one of the canned ACL policies supported by S3 and would allow anyone to read the file.