Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Confusing documentation from Python Boto3 to create bucket?

As per the Request Syntax in below link, we can pass ACL parameter to create_bucket method with ACL as ‘public-read’.

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3/client/create_bucket.html

but when I pass it giving the error as

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

botocore.exceptions.ClientError: An error occurred (InvalidBucketAclWithBlockPublicAccessError) when calling the CreateBucket operation: Bucket cannot have public ACLs set with BlockPublicAccess enabled

If the "public-read" can raise that error, why it mentioned about that option in the documentation? We can simply call "put_public_access_block" and then "put_bucket_acl" methods right?

Below is code sample of what I tried

def create_bucket(bucket_name, acl):
    bucket = boto3.client('s3')

    response = bucket.create_bucket(
        Bucket=bucket_name,
        ObjectOwnership='BucketOwnerPreferred',
        ACL=acl,
        CreateBucketConfiguration={
            'LocationConstraint':'us-west-1',

        }
    )

create_bucket('sample_bucket', 'public-read')

Account level setting for block public access
Account level setting for block public access

>Solution :

This behavior is in accordance with the design of Amazon S3 and its security best practices.

The documentation you referred to mentions the ‘public-read’ option for the ACL parameter because it represents one of the possible ACL configurations that can be used with S3 buckets. However, it’s important to note that the ‘public-read’ ACL is incompatible with Block Public Access settings.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading