diff --git a/MANIFEST.in b/MANIFEST.in index eeed788f7a3e..5d7f044782d1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,7 @@ include README.md LICENSE AUTHORS.md include requirements.txt requirements-dev.txt include moto/config/resources/aws_managed_rules.json +include moto/core/regions.json include moto/ec2/_models/*.py include moto/ec2/resources/instance_types.json include moto/ec2/resources/instance_type_offerings/*/*.json diff --git a/moto/budgets/models.py b/moto/budgets/models.py index d9d2388cce93..0847035b1a87 100644 --- a/moto/budgets/models.py +++ b/moto/budgets/models.py @@ -141,5 +141,5 @@ def describe_notifications_for_budget( budgets_backends = BackendDict( - BudgetsBackend, "budgets", use_boto3_regions=False, additional_regions=["global"] + BudgetsBackend, "budgets", use_ssm_regions=False, additional_regions=["global"] ) diff --git a/moto/ce/models.py b/moto/ce/models.py index a4a37e589b54..3e2744851939 100644 --- a/moto/ce/models.py +++ b/moto/ce/models.py @@ -153,5 +153,5 @@ def untag_resource(self, resource_arn: str, tag_keys: List[str]) -> None: ce_backends = BackendDict( - CostExplorerBackend, "ce", use_boto3_regions=False, additional_regions=["global"] + CostExplorerBackend, "ce", use_ssm_regions=False, additional_regions=["global"] ) diff --git a/moto/cloudfront/models.py b/moto/cloudfront/models.py index 3705754253eb..35cd6364e75c 100644 --- a/moto/cloudfront/models.py +++ b/moto/cloudfront/models.py @@ -432,6 +432,6 @@ def delete_origin_access_control(self, control_id: str) -> None: cloudfront_backends = BackendDict( CloudFrontBackend, "cloudfront", - use_boto3_regions=False, + use_ssm_regions=False, additional_regions=["global"], ) diff --git a/moto/core/base_backend.py b/moto/core/base_backend.py index b694b37e70f0..d3def77b95e4 100644 --- a/moto/core/base_backend.py +++ b/moto/core/base_backend.py @@ -1,4 +1,3 @@ -from boto3 import Session import re import string from functools import lru_cache @@ -6,10 +5,14 @@ from typing import Any, List, Dict, Optional, ClassVar, TypeVar, Iterator from uuid import uuid4 from moto.settings import allow_unknown_region, enable_iso_regions +from moto.utilities.utils import load_resource from .model_instances import model_data from .utils import convert_regex_to_flask_path +regions_by_service = load_resource(__name__, "regions.json") + + class InstanceTrackerMeta(type): def __new__(meta, name: str, bases: Any, dct: Dict[str, Any]) -> type: cls = super(InstanceTrackerMeta, meta).__new__(meta, name, bases, dct) @@ -191,19 +194,17 @@ def __init__( service_name: str, account_id: str, backend: type, - use_boto3_regions: bool, + use_ssm_regions: bool, additional_regions: Optional[List[str]], ): self.service_name = service_name self.account_id = account_id self.backend = backend self.regions = [] - if use_boto3_regions: - sess = Session() - for partition in sess.get_available_partitions(): - self.regions.extend( - sess.get_available_regions(service_name, partition_name=partition) - ) + if use_ssm_regions: + self.regions.extend( + regions_by_service.get(service_name) or regions_by_service["__all"] + ) self.regions.extend(additional_regions or []) self._id = str(uuid4()) @@ -268,12 +269,12 @@ def __init__( self, backend: Any, service_name: str, - use_boto3_regions: bool = True, + use_ssm_regions: bool = True, additional_regions: Optional[List[str]] = None, ): self.backend = backend self.service_name = service_name - self._use_boto3_regions = use_boto3_regions + self._use_ssm_regions = use_ssm_regions self._additional_regions = additional_regions self._id = str(uuid4()) @@ -312,6 +313,6 @@ def _create_account_specific_backend(self, account_id: str) -> None: service_name=self.service_name, account_id=account_id, backend=self.backend, - use_boto3_regions=self._use_boto3_regions, + use_ssm_regions=self._use_ssm_regions, additional_regions=self._additional_regions, ) diff --git a/moto/core/regions.json b/moto/core/regions.json new file mode 100644 index 000000000000..2c5f53d6ae00 --- /dev/null +++ b/moto/core/regions.json @@ -0,0 +1,59 @@ +{ + "__all": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-south-2", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ap-southeast-4", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-central-2", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-2", "eu-west-3", "me-central-1", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "acm-pca": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-south-2", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ap-southeast-4", "ca-central-1", "eu-central-1", "eu-central-2", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-2", "eu-west-3", "me-central-1", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "apigatewayv2": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-south-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "application-autoscaling": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-south-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "appsync": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-south-2", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-central-2", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-2", "eu-west-3", "me-central-1", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2"], + "aps": ["ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-west-2"], + "athena": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-south-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "batch": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-south-2", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-central-2", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-2", "eu-west-3", "me-central-1", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "budgets": ["ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2"], + "cloudfront": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-south-2", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ap-southeast-4", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-central-2", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-2", "eu-west-3", "me-central-1", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2"], + "codecommit": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-south-2", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-south-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-central-1", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "codepipeline": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-central-1", "eu-central-2", "eu-north-1", "eu-south-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "cognito-identity": ["ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-north-1", "eu-central-1", "eu-north-1", "eu-south-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-west-1", "us-west-1", "us-west-2"], + "cognito-idp": ["ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-central-1", "eu-north-1", "eu-south-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-west-1", "us-west-1", "us-west-2"], + "comprehend": ["ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-central-1", "eu-west-1", "eu-west-2", "us-east-1", "us-east-2", "us-gov-west-1", "us-west-2"], + "costexplorer": ["cn-northwest-1", "us-east-1"], + "databrew": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-south-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-gov-west-1", "us-west-1", "us-west-2"], + "datapipeline": ["ap-northeast-1", "ap-southeast-2", "eu-west-1", "us-east-1", "us-west-2"], + "dax": ["ap-northeast-1", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2"], + "efs": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-south-2", "ap-southeast-1", "ap-southeast-2", "ap-southeast-4", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-central-2", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-2", "eu-west-3", "me-central-1", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "elasticbeanstalk": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-south-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "elastictranscoder": ["ap-northeast-1", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "eu-west-1", "us-east-1", "us-west-1", "us-west-2"], + "emr-containers": ["ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "emr-serverless": ["ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2"], + "forecast": ["ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "eu-central-1", "eu-west-1", "us-east-1", "us-east-2", "us-west-2"], + "glacier": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-south-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "glue": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-central-2", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-2", "eu-west-3", "me-central-1", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "greengrass": ["ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-north-1", "eu-central-1", "eu-west-1", "eu-west-2", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-2"], + "identitystore": ["af-south-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ca-central-1", "eu-central-1", "eu-north-1", "eu-south-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-2"], + "iot": ["ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-central-1", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "iot-data": ["ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-central-1", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "kinesisvideo": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-north-1", "eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-west-2"], + "lakeformation": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-central-2", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-2", "eu-west-3", "me-central-1", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "managedblockchain": ["ap-northeast-1", "ap-northeast-2", "ap-southeast-1", "eu-west-1", "eu-west-2", "us-east-1", "us-gov-west-1"], + "mediaconnect": ["ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2"], + "medialive": ["ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-west-2"], + "mediapackage": ["ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2"], + "mediastore": ["ap-northeast-1", "ap-northeast-2", "ap-southeast-2", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "us-east-1", "us-west-2"], + "mediastore-data": ["ap-northeast-1", "ap-northeast-2", "ap-southeast-2", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "us-east-1", "us-west-2"], + "meteringmarketplace": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-south-2", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ap-southeast-4", "ca-central-1", "eu-central-1", "eu-central-2", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-2", "eu-west-3", "me-central-1", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "neptune": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "opsworks": ["ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2"], + "personalize": ["ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-north-1", "eu-central-1", "eu-west-1", "us-east-1", "us-east-2", "us-west-2"], + "pinpoint": ["ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-central-1", "eu-west-1", "eu-west-2", "us-east-1", "us-east-2", "us-gov-west-1", "us-west-2"], + "polly": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-west-1", "us-west-1", "us-west-2"], + "quicksight": ["ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-gov-west-1", "us-west-2"], + "rds-data": ["ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3", "us-east-1", "us-east-2", "us-west-1", "us-west-2"], + "rekognition": ["ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-central-1", "eu-west-1", "eu-west-2", "us-east-1", "us-east-2", "us-gov-west-1", "us-west-1", "us-west-2"], + "route53": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-south-2", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ap-southeast-4", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-central-2", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-2", "eu-west-3", "me-central-1", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2"], + "s3control": ["ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "scheduler": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-south-2", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ap-southeast-4", "ca-central-1", "eu-central-1", "eu-central-2", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-2", "eu-west-3", "me-central-1", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2"], + "sdb": ["ap-northeast-1", "ap-southeast-1", "ap-southeast-2", "eu-west-1", "sa-east-1", "us-east-1", "us-west-1", "us-west-2"], + "ses": ["af-south-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ca-central-1", "eu-central-1", "eu-north-1", "eu-south-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-west-1", "us-west-1", "us-west-2"], + "signer": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-south-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2"], + "textract": ["ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"], + "timestream-write": ["ap-northeast-1", "ap-southeast-2", "eu-central-1", "eu-west-1", "us-east-1", "us-east-2", "us-gov-west-1", "us-west-2"], + "transcribe": ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "cn-north-1", "cn-northwest-1", "eu-central-1", "eu-north-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1", "us-east-1", "us-east-2", "us-gov-east-1", "us-gov-west-1", "us-west-1", "us-west-2"] +} \ No newline at end of file diff --git a/moto/dynamodb_v20111205/models.py b/moto/dynamodb_v20111205/models.py index 89f5b294ccba..2880944d1c5c 100644 --- a/moto/dynamodb_v20111205/models.py +++ b/moto/dynamodb_v20111205/models.py @@ -393,6 +393,6 @@ def update_item( dynamodb_backends = BackendDict( DynamoDBBackend, "dynamodb_v20111205", - use_boto3_regions=False, + use_ssm_regions=False, additional_regions=["global"], ) diff --git a/moto/iam/models.py b/moto/iam/models.py index 3fb270f8e25f..d5d060bf0327 100644 --- a/moto/iam/models.py +++ b/moto/iam/models.py @@ -3310,5 +3310,5 @@ def get_service_linked_role_deletion_status(self) -> bool: iam_backends = BackendDict( - IAMBackend, "iam", use_boto3_regions=False, additional_regions=["global"] + IAMBackend, "iam", use_ssm_regions=False, additional_regions=["global"] ) diff --git a/moto/instance_metadata/models.py b/moto/instance_metadata/models.py index 76e4b8dfebde..74ea5a3e4cb0 100644 --- a/moto/instance_metadata/models.py +++ b/moto/instance_metadata/models.py @@ -8,6 +8,6 @@ class InstanceMetadataBackend(BaseBackend): instance_metadata_backends = BackendDict( InstanceMetadataBackend, "instance_metadata", - use_boto3_regions=False, + use_ssm_regions=False, additional_regions=["global"], ) diff --git a/moto/organizations/models.py b/moto/organizations/models.py index 21c09f5aeb32..8de2137b3589 100644 --- a/moto/organizations/models.py +++ b/moto/organizations/models.py @@ -940,6 +940,6 @@ def remove_account_from_organization(self, **kwargs: str) -> None: organizations_backends = BackendDict( OrganizationsBackend, "organizations", - use_boto3_regions=False, + use_ssm_regions=False, additional_regions=["global"], ) diff --git a/moto/route53/models.py b/moto/route53/models.py index a6077cfb27b0..1a59a4494ee6 100644 --- a/moto/route53/models.py +++ b/moto/route53/models.py @@ -929,5 +929,5 @@ def get_reusable_delegation_set(self, delegation_set_id: str) -> DelegationSet: route53_backends = BackendDict( - Route53Backend, "route53", use_boto3_regions=False, additional_regions=["global"] + Route53Backend, "route53", use_ssm_regions=False, additional_regions=["global"] ) diff --git a/moto/s3/models.py b/moto/s3/models.py index ac73475f0afa..78011ae4a73d 100644 --- a/moto/s3/models.py +++ b/moto/s3/models.py @@ -2619,10 +2619,10 @@ def __init__( self, backend: Any, service_name: str, - use_boto3_regions: bool = True, + use_ssm_regions: bool = True, additional_regions: Optional[List[str]] = None, ): - super().__init__(backend, service_name, use_boto3_regions, additional_regions) + super().__init__(backend, service_name, use_ssm_regions, additional_regions) # Maps bucket names to account IDs. This is used to locate the exact S3Backend # holding the bucket and to maintain the common bucket namespace. @@ -2630,5 +2630,5 @@ def __init__( s3_backends = S3BackendDict( - S3Backend, service_name="s3", use_boto3_regions=False, additional_regions=["global"] + S3Backend, service_name="s3", use_ssm_regions=False, additional_regions=["global"] ) diff --git a/moto/s3control/models.py b/moto/s3control/models.py index cb4bfd786f24..9446d59f8a61 100644 --- a/moto/s3control/models.py +++ b/moto/s3control/models.py @@ -142,6 +142,6 @@ def get_access_point_policy_status(self, account_id: str, name: str) -> bool: s3control_backends = BackendDict( S3ControlBackend, "s3control", - use_boto3_regions=False, + use_ssm_regions=False, additional_regions=["global"], ) diff --git a/moto/sts/models.py b/moto/sts/models.py index b465b0039b13..779f15bbef77 100644 --- a/moto/sts/models.py +++ b/moto/sts/models.py @@ -198,5 +198,5 @@ def _create_access_key(self, role: str) -> Tuple[str, AccessKey]: sts_backends = BackendDict( - STSBackend, "sts", use_boto3_regions=False, additional_regions=["global"] + STSBackend, "sts", use_ssm_regions=False, additional_regions=["global"] ) diff --git a/moto/support/models.py b/moto/support/models.py index 852e94a8cb97..b8920e02e31b 100644 --- a/moto/support/models.py +++ b/moto/support/models.py @@ -224,5 +224,5 @@ def describe_cases( support_backends = BackendDict( - SupportBackend, "support", use_boto3_regions=False, additional_regions=["us-east-1"] + SupportBackend, "support", use_ssm_regions=False, additional_regions=["us-east-1"] ) diff --git a/scripts/ssm_get_default_params.py b/scripts/ssm_get_default_params.py index b995bece4361..ed455740485f 100755 --- a/scripts/ssm_get_default_params.py +++ b/scripts/ssm_get_default_params.py @@ -4,9 +4,23 @@ import subprocess import time +import moto +from moto.utilities.utils import load_resource from moto.ssm.utils import convert_to_tree +root_dir = subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode().strip() + + +alt_names = { + "lambda": "awslambda", + "aps": "amp", # Prometheus + "costexplorer": "ce", + "waf": "wafv2", + "identitystore": "ssoadmin" +} + + def retrieve_by_path(client, path): print(f"Retrieving all parameters from {path}. " f"AWS has around 14000 parameters, and we can only retrieve 10 at the time, so this may take a while.\n\n") @@ -44,17 +58,38 @@ def main(): for path in default_param_paths: params = retrieve_by_path(client, path) tree = convert_to_tree(params) - root_dir = ( - subprocess.check_output(["git", "rev-parse", "--show-toplevel"]) - .decode() - .strip() - ) + filename = "{}.json".format(path.split("/")[-1]) dest = os.path.join(root_dir, "moto/ssm/resources/{}".format(filename)) print("Writing data to {0}".format(dest)) with open(dest, "w") as open_file: json.dump(tree, open_file, sort_keys=True, indent=2) + services = load_resource(moto.__name__, "ssm/resources/services.json")["aws"]["service"]["global-infrastructure"]["services"] + all_regions = set() + for service in services.keys(): + all_regions.update(list(services[service].get("regions", {}).keys())) + + regions_by_service = {"__all": list(all_regions)} + for service in services.keys(): + regions = set(services[service].get("regions", {}).keys()) + if regions != set(regions_by_service["__all"]): + clean_name = alt_names.get(service, service).replace("-", "") + if f"mock_{clean_name}" in dir(moto): + regions_by_service[service] = sorted(regions) + + dest = os.path.join(root_dir, "moto/core/regions.json") + print("Writing data to {0}".format(dest)) + with open(dest, "w") as open_file: + # Yes, json.dump exists + # But this gives us more control over the indentation options + open_file.write("{\n") + for idx, key in enumerate(sorted(regions_by_service.keys())): + open_file.write(f" \"{key}\": [") + open_file.write(", ".join([f"\"{s}\"" for s in sorted(regions_by_service[key])])) + open_file.write("]\n" if (idx == len(regions_by_service.keys())-1) else "],\n") + open_file.write("}") + if __name__ == "__main__": main() diff --git a/tests/test_core/test_backenddict.py b/tests/test_core/test_backenddict.py index afe1e930b453..9745fcaafce3 100644 --- a/tests/test_core/test_backenddict.py +++ b/tests/test_core/test_backenddict.py @@ -57,7 +57,7 @@ def test_backend_dict_can_retrieve_for_specific_account(): def test_backend_dict_can_ignore_boto3_regions(): - backend_dict = BackendDict(ExampleBackend, "ec2", use_boto3_regions=False) + backend_dict = BackendDict(ExampleBackend, "ec2", use_ssm_regions=False) assert backend_dict["account"].get("us-east-1") is None @@ -143,7 +143,7 @@ def _create_asb(account_id, backend=None, use_boto3_regions=False, regions=None) service_name="ec2", account_id=account_id, backend=backend or ExampleBackend, - use_boto3_regions=use_boto3_regions, + use_ssm_regions=use_boto3_regions, additional_regions=regions, )