Version: moto: 1.3.15; botocore: 1.17.56
python 3.7.4
was working before with moto 1.3.14, but stopped working in 1.3.15
error:
``` if http.status_code >= 300:
error_code = parsed_response.get("Error", {}).get("Code")
error_class = self.exceptions.from_code(error_code)
raise error_class(parsed_response, operation_name)E 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.
../../../.venv/lib/python3.7/site-packages/botocore/client.py:656: ClientError
test as below:
@pytest.fixture(scope='class')
def s3_client(self):
s3_client = boto3.client('s3', region_name='ap-southeast-2')
yield s3_client
@mock_s3
def test_store_new_supplier_file(self, config, s3_client):
s3_client.create_bucket(Bucket='test')
```
Hi @changliuit, this mimics the behaviour from AWS itself.
If the region is anything else then the default (us-east-1), the Location has to be specified using the CreateBucketConfigurationOption. See this example: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-example-creating-buckets.html
Hey @bblommers thanks for your reply! Right now the create_bucket is not exactly the same behaviour as the boto one which allows region=None in create_bucket function. Can we have something here similar to the boto code -- if region is None, get it from the client?
Regards
Chang
Hi @changliuit, I wasn't aware of the region=None behaviour! Will mark it as an enhancement
thanks @bblommers that'll be great
I understand I can work around this by specifying a region, but I choose not to (I have too many create_bucket calls in my unit tests, and running on moto 1.3.14 for a while longer is the lesser evil), and so this is effectively preventing me from upgrading to moto 1.3.16. :(
Hi @changliuit, can you share an example test of the region=none?
I assumed you meant s3.create_bucket(Bucket=bucket_name, CreateBucketConfiguration={"LocationConstraint": None},), but that doesn't work anyway.
Moto 1.3.16 also fails for s3.create_bucket(Bucket=bucket_name).
I got this error with mocking S3, seems to be the trick that the mocked S3 client only accepts region us-east-1. As it is a mocked bucket it doesn't matter..
conn = boto3.resource("s3", region_name="us-east-1")
conn.create_bucket(Bucket=os.environ["S3_BUCKET_NAME"]
I got this error even with setting to region=ap-northeast-1.
Don't forget tokyo!
Most helpful comment
Hi @changliuit, I wasn't aware of the region=None behaviour! Will mark it as an enhancement