An AWS wat?!

tl;dr different AWS regions have different APIs.

I've been using AWS via boto3 a bunch lately and testing can be a bit of a pain. To my great joy, there turns out to be a mock aws implementation: moto.

Moto support for boto is pretty good but support for boto3 is still a bit of a work in progress. In testing, I was finding a lot of functionality to be broken, in spite of it working for other people. Through some poking and digging, I discovered that the failures depended on the region.

Here's a chunk of test code that illustrates the issue:

test_moto_boto3_regions.py (Source)

import io

import boto3
import moto
import pytest


@pytest.mark.parametrize('region_name', [
    'us-east-1',
    'us-west-1',
    'us-west-2',
    'eu-west-1',
    'eu-cental-1',
    'ap-northeast-1',
    'ap-northeast-2',
    'ap-southeast-1',
    'ap-southeast-2',
    'sa-east-1',
])
@moto.mock_s3
def test_mock_s3(region_name):
    s3session = boto3.Session(region_name=region_name)
    s3res = s3session.resource('s3')
    s3bucket = s3res.Bucket('test_bucket')
    s3bucket.create()
    s3obj = s3res.Object('test_bucket', 'test_object.txt')
    s3obj.put(Body=io.BytesIO(b'abc'))
    data = s3obj.get()['Body'].read()
    assert b'abc' == data

Punchline: A call to "py.test test_moto_boto3_regions.py" gives:

test_moto_boto3_regions.py .FFF.F.FFF

====================== 7 failed, 3 passed in 0.97 seconds ======================

Why the heck are the api calls of boto3 dependent on the region being called?