6

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:

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

  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:

boto3 == 1.7.48
botocore == 1.10.84
moto == 1.3.6

After:

boto3==1.13.11
botocore==1.16.11 
moto==1.3.14  
Jamie J
  • 1,168
  • 1
  • 9
  • 22
  • There's an issue explaining the thing in more detail at `moto`'s GitHub - https://github.com/spulec/moto/issues/3292. – adrz Jul 01 '22 at 08:48

1 Answers1

15

I have no idea what changed, but I also ran into this. Here's my workaround:

Previously I had:

    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

    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

tahnok
  • 447
  • 5
  • 11
  • 4
    Saved the day!! – marcuse Oct 28 '20 at 18:11
  • Rather use the code example here: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-example-creating-buckets.html as doing the above will make your tests semantically incorrect. – Banoona Jul 21 '22 at 10:12