diff --git a/moto/backend_index.py b/moto/backend_index.py index 81bc73472c9f..78a888e94b20 100644 --- a/moto/backend_index.py +++ b/moto/backend_index.py @@ -49,6 +49,7 @@ ("ds", re.compile("https?://ds\\.(.+)\\.amazonaws\\.com")), ("dsql", re.compile("https?://dsql\\.(.+)\\.api\\.aws")), ("dynamodb", re.compile("https?://dynamodb\\.(.+)\\.amazonaws\\.com")), + ("dynamodb", re.compile("https?://(.+).ddb\\.(.+)\\.amazonaws\\.com")), ( "dynamodbstreams", re.compile("https?://streams\\.dynamodb\\.(.+)\\.amazonaws.com"), diff --git a/moto/dynamodb/urls.py b/moto/dynamodb/urls.py index 59f70de77a5d..a8c632e4926b 100644 --- a/moto/dynamodb/urls.py +++ b/moto/dynamodb/urls.py @@ -1,5 +1,8 @@ from .responses import DynamoHandler -url_bases = [r"https?://dynamodb\.(.+)\.amazonaws\.com"] +url_bases = [ + r"https?://dynamodb\.(.+)\.amazonaws\.com", + r"https?://(.+).ddb\.(.+)\.amazonaws\.com", +] url_paths = {"{0}/": DynamoHandler.dispatch} diff --git a/tests/test_dynamodb/test_dynamodb_account_mode.py b/tests/test_dynamodb/test_dynamodb_account_mode.py new file mode 100644 index 000000000000..9d9289f10aca --- /dev/null +++ b/tests/test_dynamodb/test_dynamodb_account_mode.py @@ -0,0 +1,26 @@ +import boto3 +import pytest +from botocore.config import Config + +from moto import mock_aws +from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID + + +@mock_aws +@pytest.mark.parametrize("endpoint_mode", ["disabled", "preferred", "required"]) +def test_dynamodb_with_account_id_routing(endpoint_mode): + endpoint_config = Config(account_id_endpoint_mode=endpoint_mode) + client = boto3.client( + "dynamodb", + aws_access_key_id="ACCESS_KEY", + aws_secret_access_key="SECRET_KEY", + aws_account_id=ACCOUNT_ID, + region_name="us-west-2", + config=endpoint_config, + ) + client.create_table( + TableName="test", + KeySchema=[{"AttributeName": "id", "KeyType": "HASH"}], + AttributeDefinitions=[{"AttributeName": "id", "AttributeType": "S"}], + ProvisionedThroughput={"ReadCapacityUnits": 5, "WriteCapacityUnits": 5}, + )