Question:
I have upgraded boto3 from boto3==1.7.48 to 1.13.11
, and this has broken all of my tests that use Moto. It looks like (worryingly) the mock has stopped working altogether and is trying to actually access s3, here is an example test function that was previously working:
1 2 3 4 5 6 7 8 9 10 11 12 |
def upload_video(self, video): s3 = boto3.client("s3") s3.create_bucket(Bucket=settings.AWS_STORAGE_BUCKET_NAME) for media_key in video.upload_media_keys: s3.upload_file( os.path.join( os.path.dirname(os.path.realpath(__file__)), "assets/test.mp4" ), settings.AWS_STORAGE_BUCKET_NAME, media_key, ) |
But it now gives this error
1 2 3 4 5 6 7 8 |
File "{path}", line 52, in upload_video s3.create_bucket(Bucket=settings.AWS_STORAGE_BUCKET_NAME) File "{path}/lib/python3.7/site-packages/botocore/client.py", line 316, in _api_call return self._make_api_call(operation_name, kwargs) File "{path}/lib/python3.7/site-packages/botocore/client.py", line 635, in _make_api_call raise error_class(parsed_response, operation_name) 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. |
Any help would be greatly appreciated. Here is the list of upgrades:
Before:
1 2 3 4 |
boto3 == 1.7.48 botocore == 1.10.84 moto == 1.3.6 |
After:
1 2 3 4 |
boto3==1.13.11 botocore==1.16.11 moto==1.3.14 |
Answer:
I have no idea what changed, but I also ran into this. Here’s my workaround:
Previously I had:
1 2 3 |
conn = boto3.resource("s3", region_name="ca-central-1") conn.create_bucket(Bucket=os.environ["S3_BUCKET_NAME"] |
but I changed the region to us-east-1
and everything worked
1 2 3 |
conn = boto3.resource("s3", region_name="us-east-1") conn.create_bucket(Bucket=os.environ["S3_BUCKET_NAME"] |
Since this is just a fake bucket for testing, I see no harm in using a different region if it makes things work