I want to make a folder called img
that already exists within my private bucket public. I'm using Boto3. I just want to make this folder public not anything else using a script..
This is how I'm currently connecting to the bucket and how far I have got....
ACCESS_KEY_ID = 'xxxxx'
ACCESS_KEY_SECRET = 'xxxx'
bucket_name = 'mybucket'
sourceDir = "../../docs/buildHTML/html/"
destDir = ''
r = boto3.setup_default_session(region_name='eu-west-1')
s3 = boto3.resource('s3', aws_access_key_id=ACCESS_KEY_ID, aws_secret_access_key=ACCESS_KEY_SECRET)
bucket = s3.Bucket(bucket_name)
So I have the bucket and this works. How do I now make the folder img
that already exists public?
You need to add a policy to the bucket, something like this:
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"PublicReadImages",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::mybucket/abc/img/*"]
}
]
}
You can do this through the AWS console, or any of the SDKs. In boto3, I think you do it like this:
bucket = s3.Bucket(bucket_name)
response = bucket.put(
Policy = '<policy string here>'
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With