How to upload a file to S3 and make it public using boto3? How to upload a file to S3 and make it public using boto3? python python

How to upload a file to S3 and make it public using boto3?


To upload and set permission to publicly-readable in one step, you can use:

bucket.upload_file(file, key, ExtraArgs={'ACL':'public-read'})

See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-uploading-files.html#the-extraargs-parameter


I was able to do it using objectAcl API:

s3 = boto3.resource('s3')object_acl = s3.ObjectAcl('bucket_name','object_key')response = object_acl.put(ACL='public-read')

For details: http://boto3.readthedocs.io/en/latest/reference/services/s3.html#objectacl


Adi's way works. However, if you were like me, you might have run into an access denied issue. This is normally caused by broken permissions of the user. I fixed it by adding the following to the Action array:

"s3:GetObjectAcl","s3:PutObjectAcl"