Skip to content

Commit

Permalink
DynamoDB: Support AccountMode (#8621)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers authored Feb 26, 2025
1 parent 1ced10f commit a1af2a8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions moto/backend_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
5 changes: 4 additions & 1 deletion moto/dynamodb/urls.py
Original file line number Diff line number Diff line change
@@ -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}
26 changes: 26 additions & 0 deletions tests/test_dynamodb/test_dynamodb_account_mode.py
Original file line number Diff line number Diff line change
@@ -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},
)

0 comments on commit a1af2a8

Please sign in to comment.