Skip to content
This repository has been archived by the owner on Aug 27, 2023. It is now read-only.

IllegalLocationConstraintException when using s3 and specifying region #215

Open
jpc2350 opened this issue Jun 4, 2019 · 3 comments
Open

Comments

@jpc2350
Copy link

jpc2350 commented Jun 4, 2019

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
Copy link
Author

jpc2350 commented Jun 4, 2019

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

@renehennig
Copy link

I tried to fix that: dcdfd5f

@nivintw
Copy link

nivintw commented Sep 28, 2022

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants