- Newest
- Most votes
- Most comments
Sorry, I just checked the documentation and it looks like the default setting is to deny public access.
https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-control-block-public-access.html
By default, new buckets, access points, and objects don't allow public access.
In other words, after the bucket is created, the public access settings need to be disabled and the ACLs set, so the code should look like the following.
s3X.create_bucket(Bucket=’my_bucket_name’,ObjectOwnership='ObjectWriter')
s3X.put_public_access_block(Bucket=bucket_name, PublicAccessBlockConfiguration={'BlockPublicAcls': False,'IgnorePublicAcls': False,'BlockPublicPolicy': False,'RestrictPublicBuckets': False})
s3X.put_bucket_acl(ACL='public-read-write',Bucket=’my_bucket_name’)
Try changing the code as follows.
The error occurs when ObjectOwnership is "BucketOwnerEnforced".
s3X.create_bucket(Bucket=’my_bucket_name’, ACL=’public-read-write’, ObjectOwnership='ObjectWriter')
BucketOwnerEnforced" is changed to "ObjectWriter" because ACLs are disabled and an error occurs when ACL settings are inserted.
Still generating an error message: 'botocore.exceptions.ClientError: An error occurred (InvalidBucketAclWithBlockPublicAccessError) when calling the CreateBucket operation: Bucket cannot have public ACLs set with BlockPublicAccess enabled'
Sorry, I just checked the documentation and it looks like the default setting is to deny public access. https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-control-block-public-access.html
By default, new buckets, access points, and objects don't allow public access.
In other words, after the bucket is created, the public access settings need to be disabled and the ACLs set, so the code should look like the following.
s3X.create_bucket(Bucket=’my_bucket_name’,ObjectOwnership='ObjectWriter') s3X.put_public_access_block(Bucket=bucket_name, PublicAccessBlockConfiguration={'BlockPublicAcls': False,'IgnorePublicAcls': False,'BlockPublicPolicy': False,'RestrictPublicBuckets': False}) s3X.put_bucket_acl(ACL='public-read-write',Bucket=’my_bucket_name’)
Relevant content
- Accepted Answerasked 2 months ago
- asked 2 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 10 months ago
- AWS OFFICIALUpdated 2 years ago
Your code is trying to create an S3 bucket with "resource". As per the following documentation, "client" is used to create S3 buckets. https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#client
So the full code is as follows.
Since "resource" does not seem to have "put_public_access_block", I created a code to use "client" as well.
@Riku_Kobayashi: Using 'resource' is preferable when integrated into python projects (which is the case), but if resource doesn't have the put_public_access_method (and probably others), I guess that you can use 'client' or a combination of 'client' and 'resource.' Thanks.