pypicloud icon indicating copy to clipboard operation
pypicloud copied to clipboard

IllegalLocationConstraintException when using s3 and specifying region

Open jpc2350 opened this issue 5 years ago • 3 comments

Hi,

I'm trying to use s3 as a storage backend, utilising storage.region_name to specify a region in which to place the bucket (eu-west-1).

HeadBucket is failing as expected, which means it's then trying to create the bucket, but is failing with

botocore.exceptions.ClientError: An error occurred (IllegalLocationConstraintException) when calling the CreateBucket operation: The unspecified location constraint is incompatible for the region specific endpoint this request was sent to.

It looks like boto3 requires CreateBucketConfiguration={'LocationConstraint':'eu-west-1'} to be specified in the bucket.create() function - but this is not possible currently.

Is there a way to get around this, or a possible fix?

pypicloud version = 1.0.11

jpc2350 avatar Jun 04 '19 16:06 jpc2350

So I have overcome this by creating the S3 bucket first using the AWS tools, but it is an issue, that should be fixed.

jpc2350 avatar Jun 04 '19 16:06 jpc2350

I tried to fix that: https://github.com/stevearc/pypicloud/pull/225/commits/dcdfd5f8095406775670ad363ac452e8027b3419

renehennig avatar Dec 10 '19 14:12 renehennig

Interestingly, the update made above actually causes bucket creating in us-east-1 to fail now. Frustratingly, us-east-1 is actually not a valid option for LocationConstratint per: https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html

a minor patch to check the region_name before setting location_constraint will remove this unexpected hiccup. AWS is definitely partially to blame here... having the "default" be invalid makes me SMH.

I think I got around this by only setting the config option if it is not us-east-1 through the helm chart I use, but that seems like a bit of silly "gotcha" that people will trip over.

I also resorted to manually creating through the UI before figuring out what was going on, and it's definitely less than ideal user experience.

Suggested code:

 if config.region_name and config.region_name != "us-east-1":
                    location = {'LocationConstraint': config.region_name}
                    bucket.create(CreateBucketConfiguration=location)
                else:
                    bucket.create()

Might open a PR for this unless someone gets to it before me

nivintw avatar Sep 28 '22 06:09 nivintw