Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
feat: multi-tenancy state isolation, graceful Docker cleanup on shutdown (#200)
Nahuel Nucera7fe76cb014a8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 724cb8e6..5de11e6c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,18 @@ Versioning follows [Semantic Versioning](https://semver.org/).---+## [1.1.56] — 2026-04-09++### Added+- **Multi-tenancy state isolation** — resources with the same name in different accounts no longer collide. All service state dicts use `AccountScopedDict` which namespaces by account ID automatically. Previously, multi-tenancy (v1.1.54) only changed ARN generation — the underlying state was shared. Now IAM roles, S3 buckets, SQS queues, DynamoDB tables, and all other resources are fully isolated per account. Reported by community feedback.+- **Graceful Docker container cleanup on shutdown** — RDS, ECS, and ElastiCache Docker containers are now stopped and removed when MiniStack shuts down, using Docker labels (`ministack=rds`, `ministack=ecs`, `ministack=elasticache`). Previously containers were orphaned unless `/_ministack/reset` was called explicitly.++### Fixed+- **SQS queue tags not saved on CreateQueue** — tags passed at queue creation time were silently ignored. `ListQueueTags` now returns tags set during `CreateQueue` for both JSON and Query API protocols. Reported by @jfisbein+- **PERSIST_STATE compatibility with AccountScopedDict** — state serialization and deserialization now handle the new scoped dict format correctly. All 37 service state files save and restore across restarts.++---+## [1.1.55] — 2026-04-09### Fixeddiff --git a/README.md b/README.mdindex e7055255..6ac6062c 100644--- a/README.md+++ b/README.md@@ -108,7 +108,7 @@ aws --endpoint-url=http://localhost:4566 sts get-caller-identity# → { "Account": "222222222222", ... }```-All ARNs (SQS queues, Lambda functions, IAM roles, etc.) reflect the caller's account ID. This allows multiple developers or CI pipelines to share a single MiniStack endpoint with isolated namespaces — no extra setup needed.+All ARNs and resource state (SQS queues, Lambda functions, IAM roles, S3 buckets, DynamoDB tables, etc.) are fully isolated per account. Resources with the same name in different accounts never collide. This allows multiple developers or CI pipelines to share a single MiniStack endpoint with complete tenant isolation — no extra setup needed.| Access Key | Account ID Used ||---|---|diff --git a/ministack/app.py b/ministack/app.pyindex 151fe417..86592762 100644--- a/ministack/app.py+++ b/ministack/app.py@@ -625,10 +625,31 @@ async def _handle_lifespan(scope, receive, send):"servicediscovery": servicediscovery.get_state,"s3files": s3files.get_state,})+ _stop_docker_containers()await send({"type": "lifespan.shutdown.complete"})return+def _stop_docker_containers():+ """Stop all Docker containers managed by MiniStack (RDS, ECS, ElastiCache).+ Uses container labels to find them — does not touch service state."""+ try:+ import docker+ client = docker.from_env()+ except Exception:+ return+ for label in ("ministack=rds", "ministack=ecs", "ministack=elasticache"):+ try:+ for c in client.containers.list(filters={"label": label}):+ try:+ c.stop(timeout=5)+ c.remove(v=True)+ except Exception:+ pass+ except Exception:+ pass++def _load_persisted_state():"""Load persisted state for services that support it."""data = load_state("apigateway")diff --git a/ministack/core/persistence.py b/ministack/core/persistence.pyindex a749ca40..8f046a22 100644--- a/ministack/core/persistence.py+++ b/ministack/core/persistence.py@@ -9,12 +9,42 @@ import loggingimport osimport tempfile+from ministack.core.responses import AccountScopedDict+logger = logging.getLogger("persistence")PERSIST_STATE = os.environ.get("PERSIST_STATE", "0") == "1"STATE_DIR = os.environ.get("STATE_DIR", "/tmp/ministack-state")+def _json_default(obj):+ """JSON encoder fallback for AccountScopedDict and tuple keys."""+ if isinstance(obj, AccountScopedDict):+ # Serialize all accounts' data with string keys+ result = {}+ for k, v in obj._data.items():+ # k is (account_id, original_key) tuple+ result[f"{k[0]}\x00{k[1]!r}"] = v+ return {"__scoped__": True, "data": result}+ raise TypeError(f"Object of type {type(obj).__name__} is not JSON serializable")+++def _json_object_hook(obj):+ """JSON decoder hook to restore AccountScopedDict from serialized form."""+ if obj.get("__scoped__"):+ asd = AccountScopedDict()+ for k, v in obj["data"].items():+ account_id, key_repr = k.split("\x00", 1)+ # Restore the original key (was serialized with repr())+ try:+ original_key = eval(key_repr) # noqa: S307+ except Exception:+ original_key = key_repr+ asd._data[(account_id, original_key)] = v+ return asd+ return obj++def save_state(service: str, data: dict) -> None:if not PERSIST_STATE:return@@ -24,7 +54,7 @@ def save_state(service: str, data: dict) -> None:tmp = path + ".tmp"try:with open(tmp, "w") as f:- json.dump(data, f)+ json.dump(data, f, default=_json_default)os.replace(tmp, path)except BaseException:# Clean up temp file on any failure to avoid stale partial writes@@ -46,7 +76,7 @@ def load_state(service: str) -> dict | None:return Nonetry:with open(path) as f:- data = json.load(f)+ data = json.load(f, object_hook=_json_object_hook)logger.info("Persistence: loaded %s state from %s", service, path)return dataexcept (json.JSONDecodeError, OSError) as e:diff --git a/ministack/core/responses.py b/ministack/core/responses.pyindex 4a63d0ca..6b687d73 100644--- a/ministack/core/responses.py+++ b/ministack/core/responses.py@@ -40,6 +40,107 @@ def get_account_id() -> str:return _request_account_id.get()+class AccountScopedDict:+ """A dict-like container that namespaces keys by the current request's account ID.++ Stores data as ``{account_id}\\x00{key}`` internally so that identical+ resource names in different accounts never collide. All standard dict+ operations (get, set, delete, iteration, ``in``, ``len``) are scoped to the+ caller's account automatically via ``get_account_id()``.++ This is a drop-in replacement for ``dict`` in service module-level state,+ e.g. ``_roles = AccountScopedDict()`` instead of ``_roles: dict = {}``.+ """++ __slots__ = ("_data",)++ def __init__(self):+ self._data: dict = {}++ # -- internal helpers --------------------------------------------------++ def _scoped(self, key):+ return (get_account_id(), key)++ def _unscope(self, scoped_key):+ return scoped_key[1]++ def _prefix(self):+ return get_account_id()++ def _is_mine(self, scoped_key):+ return scoped_key[0] == get_account_id()++ # -- dict interface ----------------------------------------------------++ def __setitem__(self, key, value):+ self._data[self._scoped(key)] = value++ def __getitem__(self, key):+ return self._data[self._scoped(key)]++ def __delitem__(self, key):+ del self._data[self._scoped(key)]++ def __contains__(self, key):+ return self._scoped(key) in self._data++ def __len__(self):+ return sum(1 for k in self._data if self._is_mine(k))++ def __bool__(self):+ return any(self._is_mine(k) for k in self._data)++ def __iter__(self):+ for k in self._data:+ if self._is_mine(k):+ yield self._unscope(k)++ def get(self, key, default=None):+ return self._data.get(self._scoped(key), default)++ def pop(self, key, *args):+ return self._data.pop(self._scoped(key), *args)++ def setdefault(self, key, default=None):+ return self._data.setdefault(self._scoped(key), default)++ def keys(self):+ return [self._unscope(k) for k in self._data if self._is_mine(k)]++ def values(self):+ return [v for k, v in self._data.items() if self._is_mine(k)]++ def items(self):+ return [(self._unscope(k), v) for k, v in self._data.items() if self._is_mine(k)]++ def update(self, other):+ if isinstance(other, AccountScopedDict):+ self._data.update(other._data)+ elif isinstance(other, dict):+ for k, v in other.items():+ self[k] = v++ def clear(self):+ """Clear ALL accounts' data (used by reset)."""+ self._data.clear()++ def to_dict(self):+ """Convert ALL accounts' data to a plain dict for serialization.+ Keys are stored as (account_id, original_key) tuples."""+ return dict(self._data)++ @classmethod+ def from_dict(cls, data):+ """Restore from a plain dict produced by to_dict()."""+ obj = cls()+ obj._data = dict(data)+ return obj++ def __repr__(self):+ return f"AccountScopedDict({dict(self.items())})"++def xml_response(root_tag: str, namespace: str, children: dict, status: int = 200) -> tuple:"""Build an AWS-style XML response."""root = Element(root_tag, xmlns=namespace)diff --git a/ministack/services/acm.py b/ministack/services/acm.pyindex db1cb33b..085e073f 100644--- a/ministack/services/acm.py+++ b/ministack/services/acm.py@@ -15,13 +15,13 @@ import timefrom ministack.core.persistence import PERSIST_STATE, load_state-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid, now_iso+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuid, now_isologger = logging.getLogger("acm")REGION = os.environ.get("MINISTACK_REGION", "us-east-1")-_certificates: dict = {} # arn -> certificate dict+_certificates = AccountScopedDict() # arn -> certificate dictdef get_state():diff --git a/ministack/services/alb.py b/ministack/services/alb.pyindex 07603586..f05484ad 100644--- a/ministack/services/alb.py+++ b/ministack/services/alb.py@@ -27,7 +27,7 @@ import timefrom urllib.parse import parse_qsfrom ministack.core.persistence import PERSIST_STATE, load_state-from ministack.core.responses import get_account_id, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, new_uuidlogger = logging.getLogger("alb")@@ -37,14 +37,14 @@ NS = "http://elasticloadbalancing.amazonaws.com/doc/2015-12-01/"# ---------------------------------------------------------------------------# State# ----------------------------------------------------------------------------_lbs: dict = {} # lb_arn -> LB record-_tgs: dict = {} # tg_arn -> TG record-_listeners: dict = {} # l_arn -> Listener record-_rules: dict = {} # r_arn -> Rule record-_targets: dict = {} # tg_arn -> [target dict]-_tags: dict = {} # res_arn -> [{Key, Value}]-_lb_attrs: dict = {} # lb_arn -> [{Key, Value}]-_tg_attrs: dict = {} # tg_arn -> [{Key, Value}]+_lbs = AccountScopedDict() # lb_arn -> LB record+_tgs = AccountScopedDict() # tg_arn -> TG record+_listeners = AccountScopedDict() # l_arn -> Listener record+_rules = AccountScopedDict() # r_arn -> Rule record+_targets = AccountScopedDict() # tg_arn -> [target dict]+_tags = AccountScopedDict() # res_arn -> [{Key, Value}]+_lb_attrs = AccountScopedDict() # lb_arn -> [{Key, Value}]+_tg_attrs = AccountScopedDict() # tg_arn -> [{Key, Value}]def get_state():diff --git a/ministack/services/apigateway.py b/ministack/services/apigateway.pyindex cb92ce4c..cb4da15b 100644--- a/ministack/services/apigateway.py+++ b/ministack/services/apigateway.py@@ -49,7 +49,7 @@ import timeimport urllib.errorimport urllib.request-from ministack.core.responses import get_account_id, error_response_json, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, new_uuid_HOST = os.environ.get("MINISTACK_HOST", "localhost")_PORT = os.environ.get("GATEWAY_PORT", "4566")@@ -59,13 +59,13 @@ logger = logging.getLogger("apigateway")REGION = os.environ.get("MINISTACK_REGION", "us-east-1")# ---- Module-level state -----_apis: dict = {} # api_id -> api object-_routes: dict = {} # api_id -> {route_id -> route object}-_integrations: dict = {} # api_id -> {integration_id -> integration object}-_stages: dict = {} # api_id -> {stage_name -> stage object}-_deployments: dict = {} # api_id -> {deployment_id -> deployment object}-_authorizers: dict = {} # api_id -> {authorizer_id -> authorizer object}-_api_tags: dict = {} # resource_arn -> {key -> value}+_apis = AccountScopedDict() # api_id -> api object+_routes = AccountScopedDict() # api_id -> {route_id -> route object}+_integrations = AccountScopedDict() # api_id -> {integration_id -> integration object}+_stages = AccountScopedDict() # api_id -> {stage_name -> stage object}+_deployments = AccountScopedDict() # api_id -> {deployment_id -> deployment object}+_authorizers = AccountScopedDict() # api_id -> {authorizer_id -> authorizer object}+_api_tags = AccountScopedDict() # resource_arn -> {key -> value}# ---- Response helpers ----diff --git a/ministack/services/apigateway_v1.py b/ministack/services/apigateway_v1.pyindex a184c3d1..a866efb8 100644--- a/ministack/services/apigateway_v1.py+++ b/ministack/services/apigateway_v1.py@@ -77,7 +77,7 @@ import timeimport urllib.errorimport urllib.request-from ministack.core.responses import get_account_id, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, new_uuiddef _now_unix():@@ -91,17 +91,17 @@ logger = logging.getLogger("apigateway_v1")REGION = os.environ.get("MINISTACK_REGION", "us-east-1")# ---- Module-level state -----_rest_apis: dict = {} # rest_api_id -> RestApi-_resources: dict = {} # rest_api_id -> {resource_id -> Resource}+_rest_apis = AccountScopedDict() # rest_api_id -> RestApi+_resources = AccountScopedDict() # rest_api_id -> {resource_id -> Resource}_stages_v1: dict = {} # rest_api_id -> {stage_name -> Stage}_deployments_v1: dict = {} # rest_api_id -> {deployment_id -> Deployment}_authorizers_v1: dict = {} # rest_api_id -> {authorizer_id -> Authorizer}-_models: dict = {} # rest_api_id -> {model_id -> Model}-_api_keys: dict = {} # key_id -> ApiKey-_usage_plans: dict = {} # plan_id -> UsagePlan-_usage_plan_keys: dict = {} # plan_id -> {key_id -> UsagePlanKey}-_domain_names: dict = {} # domain_name -> DomainName-_base_path_mappings: dict = {} # domain_name -> {base_path -> BasePathMapping}+_models = AccountScopedDict() # rest_api_id -> {model_id -> Model}+_api_keys = AccountScopedDict() # key_id -> ApiKey+_usage_plans = AccountScopedDict() # plan_id -> UsagePlan+_usage_plan_keys = AccountScopedDict() # plan_id -> {key_id -> UsagePlanKey}+_domain_names = AccountScopedDict() # domain_name -> DomainName+_base_path_mappings = AccountScopedDict() # domain_name -> {base_path -> BasePathMapping}_v1_tags: dict = {} # resource_arn -> {key -> value}diff --git a/ministack/services/appsync.py b/ministack/services/appsync.pyindex f5a865e8..bae9489c 100644--- a/ministack/services/appsync.py+++ b/ministack/services/appsync.py@@ -25,7 +25,7 @@ import reimport timefrom ministack.core.persistence import PERSIST_STATE, load_state-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuidlogger = logging.getLogger("appsync")@@ -35,12 +35,12 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")# In-memory state# ----------------------------------------------------------------------------_apis: dict = {} # apiId -> api record-_api_keys: dict = {} # apiId -> {keyId -> key record}-_data_sources: dict = {} # apiId -> {name -> data source record}-_resolvers: dict = {} # apiId -> {typeName -> {fieldName -> resolver record}}-_types: dict = {} # apiId -> {typeName -> type record}-_tags: dict = {} # resource_arn -> {key: value}+_apis = AccountScopedDict() # apiId -> api record+_api_keys = AccountScopedDict() # apiId -> {keyId -> key record}+_data_sources = AccountScopedDict() # apiId -> {name -> data source record}+_resolvers = AccountScopedDict() # apiId -> {typeName -> {fieldName -> resolver record}}+_types = AccountScopedDict() # apiId -> {typeName -> type record}+_tags = AccountScopedDict() # resource_arn -> {key: value}# ---------------------------------------------------------------------------# Persistencediff --git a/ministack/services/athena.py b/ministack/services/athena.pyindex d1aa0ed0..6f5b8b2b 100644--- a/ministack/services/athena.py+++ b/ministack/services/athena.py@@ -22,7 +22,7 @@ import threadingimport timefrom ministack.core.persistence import PERSIST_STATE, load_state-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuidlogger = logging.getLogger("athena")@@ -41,7 +41,7 @@ def get_athena_engine():return engine-_executions: dict = {}+_executions = AccountScopedDict()_workgroups: dict = {"primary": {"Name": "primary",@@ -53,7 +53,7 @@ _workgroups: dict = {},}}-_named_queries: dict = {}+_named_queries = AccountScopedDict()_data_catalogs: dict = {"AwsDataCatalog": {"Name": "AwsDataCatalog",@@ -62,8 +62,8 @@ _data_catalogs: dict = {"Parameters": {},}}-_prepared_statements: dict = {} # "workgroup/name" -> statement dict-_tags: dict = {} # arn -> {key: value, ...}+_prepared_statements = AccountScopedDict() # "workgroup/name" -> statement dict+_tags = AccountScopedDict() # arn -> {key: value, ...}def get_state():diff --git a/ministack/services/cloudformation/__init__.py b/ministack/services/cloudformation/__init__.pyindex 18c7faf7..8e4522a6 100644--- a/ministack/services/cloudformation/__init__.py+++ b/ministack/services/cloudformation/__init__.py@@ -14,15 +14,17 @@ import loggingimport osfrom urllib.parse import parse_qs+from ministack.core.responses import AccountScopedDict+logger = logging.getLogger("cloudformation")REGION = os.environ.get("MINISTACK_REGION", "us-east-1")# In-memory state (shared across all submodules)-_stacks: dict = {} # stack_name -> stack dict-_stack_events: dict = {} # stack_id -> [event list]-_exports: dict = {} # export_name -> {StackId, Name, Value}-_change_sets: dict = {} # cs_id -> change set dict+_stacks = AccountScopedDict() # stack_name -> stack dict+_stack_events = AccountScopedDict() # stack_id -> [event list]+_exports = AccountScopedDict() # export_name -> {StackId, Name, Value}+_change_sets = AccountScopedDict() # cs_id -> change set dict# Re-exports for compatibilityfrom .engine import ( # noqa: E402@@ -77,4 +79,4 @@ def reset():# Must be last — handlers imports from this modulefrom .handlers import _ACTION_HANDLERS, _validate_template # noqa: E402-from ministack.core.responses import get_account_id+from ministack.core.responses import AccountScopedDict, get_account_iddiff --git a/ministack/services/cloudfront.py b/ministack/services/cloudfront.pyindex 2ee36b1a..66f1d362 100644--- a/ministack/services/cloudfront.py+++ b/ministack/services/cloudfront.py@@ -20,7 +20,7 @@ from defusedxml.ElementTree import fromstringfrom xml.etree.ElementTree import Element, SubElement, tostringfrom ministack.core.persistence import PERSIST_STATE, load_state-from ministack.core.responses import get_account_id, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, new_uuidlogger = logging.getLogger("cloudfront")@@ -39,9 +39,9 @@ _TAG_RE = re.compile(r"^/2020-05-31/tagging/?$")# ---------------------------------------------------------------------------# In-memory state# ----------------------------------------------------------------------------_distributions: dict = {} # Id -> distribution record-_invalidations: dict = {} # distribution_id -> [invalidation record, ...]-_tags: dict = {} # arn -> [{"Key": ..., "Value": ...}]+_distributions = AccountScopedDict() # Id -> distribution record+_invalidations = AccountScopedDict() # distribution_id -> [invalidation record, ...]+_tags = AccountScopedDict() # arn -> [{"Key": ..., "Value": ...}]def reset():diff --git a/ministack/services/cloudwatch.py b/ministack/services/cloudwatch.pyindex bc8830e4..34e67d79 100644--- a/ministack/services/cloudwatch.py+++ b/ministack/services/cloudwatch.py@@ -21,7 +21,7 @@ from datetime import datetime, timezonefrom urllib.parse import parse_qsfrom ministack.core.persistence import load_state, PERSIST_STATE-from ministack.core.responses import get_account_id, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, new_uuidlogger = logging.getLogger("cloudwatch")@@ -29,11 +29,11 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")TWO_WEEKS_SECONDS = 14 * 24 * 3600_metrics: dict = defaultdict(list)-_alarms: dict = {}-_composite_alarms: dict = {}+_alarms = AccountScopedDict()+_composite_alarms = AccountScopedDict()_alarm_history: list = []-_resource_tags: dict = {}-_dashboards: dict = {} # dashboard_name -> {DashboardName, DashboardBody, LastModified}+_resource_tags = AccountScopedDict()+_dashboards = AccountScopedDict() # dashboard_name -> {DashboardName, DashboardBody, LastModified}# ── Persistence ────────────────────────────────────────────diff --git a/ministack/services/cloudwatch_logs.py b/ministack/services/cloudwatch_logs.pyindex 0b4322b9..e1a92a9b 100644--- a/ministack/services/cloudwatch_logs.py+++ b/ministack/services/cloudwatch_logs.py@@ -22,7 +22,7 @@ import jsonimport loggingimport time-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuidlogger = logging.getLogger("logs")@@ -30,7 +30,7 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")from ministack.core.persistence import load_state, PERSIST_STATE-_log_groups: dict = {}+_log_groups = AccountScopedDict()# group_name -> {# arn, creationTime, retentionInDays (int|None), tags: {str: str},# subscriptionFilters: {filterName: {filterName, logGroupName, filterPattern,@@ -40,13 +40,13 @@ _log_groups: dict = {}# firstEventTimestamp, lastEventTimestamp, lastIngestionTime}},# }-_destinations: dict = {}+_destinations = AccountScopedDict()# dest_name -> {destinationName, targetArn, roleArn, accessPolicy, arn, creationTime}-_metric_filters: dict = {}+_metric_filters = AccountScopedDict()# (log_group_name, filter_name) -> {filterName, logGroupName, filterPattern, metricTransformations, creationTime}-_queries: dict = {}+_queries = AccountScopedDict()# query_id -> {queryId, logGroupName, startTime, endTime, queryString, status}diff --git a/ministack/services/cognito.py b/ministack/services/cognito.pyindex 4867d3e3..f3b11b75 100644--- a/ministack/services/cognito.py+++ b/ministack/services/cognito.py@@ -55,7 +55,7 @@ from datetime import datetime, timezonefrom urllib.parse import parse_qsfrom ministack.core.persistence import load_state, PERSIST_STATE-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuidlogger = logging.getLogger("cognito")@@ -131,7 +131,7 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")# In-memory state — User Pools (cognito-idp)# ----------------------------------------------------------------------------_user_pools: dict = {}+_user_pools = AccountScopedDict()# pool_id -> {# Id, Name, Arn, CreationDate, LastModifiedDate, Status,# Policies, Schema, AutoVerifiedAttributes, UsernameAttributes,@@ -143,13 +143,13 @@ _user_pools: dict = {}# _groups: {group_name -> group_dict},# }-_pool_domain_map: dict = {} # domain -> pool_id+_pool_domain_map = AccountScopedDict() # domain -> pool_id# ---------------------------------------------------------------------------# In-memory state — Identity Pools (cognito-identity)# ----------------------------------------------------------------------------_identity_pools: dict = {}+_identity_pools = AccountScopedDict()# identity_pool_id -> {# IdentityPoolId, IdentityPoolName, AllowUnauthenticatedIdentities,# SupportedLoginProviders, DeveloperProviderName,@@ -159,7 +159,7 @@ _identity_pools: dict = {}# _identities: {identity_id -> identity_dict},# }-_identity_tags: dict = {} # identity_pool_id -> {key: value}+_identity_tags = AccountScopedDict() # identity_pool_id -> {key: value}# ── Persistence ────────────────────────────────────────────diff --git a/ministack/services/dynamodb.py b/ministack/services/dynamodb.pyindex c0b83ce9..239a3e34 100644--- a/ministack/services/dynamodb.py+++ b/ministack/services/dynamodb.py@@ -20,6 +20,7 @@ from collections import defaultdictfrom decimal import Decimal, InvalidOperationfrom ministack.core.responses import (+ AccountScopedDict,get_account_id,error_response_json,json_response,@@ -33,10 +34,10 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")from ministack.core.persistence import load_state, PERSIST_STATE-_tables: dict = {}-_tags: dict = {}-_ttl_settings: dict = {}-_pitr_settings: dict = {}+_tables = AccountScopedDict()+_tags = AccountScopedDict()+_ttl_settings = AccountScopedDict()+_pitr_settings = AccountScopedDict()_lock = threading.Lock()@@ -64,7 +65,7 @@ if _restored:# DynamoDB Streams: table_name -> list of stream records# Each record follows the DynamoDB Streams event format consumed by Lambda ESMs.-_stream_records: dict = {}+_stream_records = AccountScopedDict()_stream_seq_counter = 0_stream_seq_lock = threading.Lock()diff --git a/ministack/services/ec2.py b/ministack/services/ec2.pyindex 19e08a39..c19eb5f6 100644--- a/ministack/services/ec2.py+++ b/ministack/services/ec2.py@@ -64,7 +64,7 @@ from urllib.parse import parse_qsfrom xml.sax.saxutils import escape as _escfrom ministack.core.persistence import load_state, PERSIST_STATE-from ministack.core.responses import get_account_id, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, new_uuidlogger = logging.getLogger("ec2")@@ -74,29 +74,29 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")# State# ----------------------------------------------------------------------------_instances: dict = {}-_security_groups: dict = {}-_key_pairs: dict = {}-_vpcs: dict = {}-_subnets: dict = {}-_internet_gateways: dict = {}-_addresses: dict = {} # allocation_id -> address record-_tags: dict = {} # resource_id -> [{"Key": ..., "Value": ...}]-_route_tables: dict = {} # rtb_id -> route table record-_network_interfaces: dict = {} # eni_id -> ENI record-_vpc_endpoints: dict = {} # vpce_id -> endpoint record-_volumes: dict = {} # vol_id -> volume record-_snapshots: dict = {} # snap_id -> snapshot record-_nat_gateways: dict = {} # nat_id -> NAT gateway record-_network_acls: dict = {} # acl_id -> network ACL record-_flow_logs: dict = {} # flow_log_id -> flow log record-_vpc_peering: dict = {} # pcx_id -> peering connection record-_dhcp_options: dict = {} # dopt_id -> DHCP options record-_egress_igws: dict = {} # eigw_id -> egress-only internet gateway record-_prefix_lists: dict = {} # pl_id -> managed prefix list record-_vpn_gateways: dict = {} # vgw_id -> VPN gateway record-_customer_gateways: dict = {} # cgw_id -> customer gateway record-_launch_templates: dict = {} # lt_id -> launch template record (includes versions list)+_instances = AccountScopedDict()+_security_groups = AccountScopedDict()+_key_pairs = AccountScopedDict()+_vpcs = AccountScopedDict()+_subnets = AccountScopedDict()+_internet_gateways = AccountScopedDict()+_addresses = AccountScopedDict() # allocation_id -> address record+_tags = AccountScopedDict() # resource_id -> [{"Key": ..., "Value": ...}]+_route_tables = AccountScopedDict() # rtb_id -> route table record+_network_interfaces = AccountScopedDict() # eni_id -> ENI record+_vpc_endpoints = AccountScopedDict() # vpce_id -> endpoint record+_volumes = AccountScopedDict() # vol_id -> volume record+_snapshots = AccountScopedDict() # snap_id -> snapshot record+_nat_gateways = AccountScopedDict() # nat_id -> NAT gateway record+_network_acls = AccountScopedDict() # acl_id -> network ACL record+_flow_logs = AccountScopedDict() # flow_log_id -> flow log record+_vpc_peering = AccountScopedDict() # pcx_id -> peering connection record+_dhcp_options = AccountScopedDict() # dopt_id -> DHCP options record+_egress_igws = AccountScopedDict() # eigw_id -> egress-only internet gateway record+_prefix_lists = AccountScopedDict() # pl_id -> managed prefix list record+_vpn_gateways = AccountScopedDict() # vgw_id -> VPN gateway record+_customer_gateways = AccountScopedDict() # cgw_id -> customer gateway record+_launch_templates = AccountScopedDict() # lt_id -> launch template record (includes versions list)# ── Persistence ────────────────────────────────────────────diff --git a/ministack/services/ecr.py b/ministack/services/ecr.pyindex 22c1123c..cf927724 100644--- a/ministack/services/ecr.py+++ b/ministack/services/ecr.py@@ -12,16 +12,16 @@ import osimport timefrom ministack.core.persistence import load_state, PERSIST_STATE-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuidlogger = logging.getLogger("ecr")REGION = os.environ.get("MINISTACK_REGION", "us-east-1")-_repositories: dict = {}-_images: dict = {}-_lifecycle_policies: dict = {}-_repo_policies: dict = {}+_repositories = AccountScopedDict()+_images = AccountScopedDict()+_lifecycle_policies = AccountScopedDict()+_repo_policies = AccountScopedDict()# ── Persistence ────────────────────────────────────────────diff --git a/ministack/services/ecs.py b/ministack/services/ecs.pyindex cbebb888..a696eb34 100644--- a/ministack/services/ecs.py+++ b/ministack/services/ecs.py@@ -31,6 +31,7 @@ import timefrom ministack.core.persistence import load_statefrom ministack.core.responses import (+ AccountScopedDict,get_account_id,error_response_json,json_response,@@ -42,14 +43,14 @@ logger = logging.getLogger("ecs")REGION = os.environ.get("MINISTACK_REGION", "us-east-1")-_clusters: dict = {}-_task_defs: dict = {}-_task_def_latest: dict = {}-_services: dict = {}-_tasks: dict = {}-_tags: dict = {}-_account_settings: dict = {}-_capacity_providers: dict = {}+_clusters = AccountScopedDict()+_task_defs = AccountScopedDict()+_task_def_latest = AccountScopedDict()+_services = AccountScopedDict()+_tasks = AccountScopedDict()+_tags = AccountScopedDict()+_account_settings = AccountScopedDict()+_capacity_providers = AccountScopedDict()_docker = None@@ -1352,7 +1353,7 @@ def _delete_account_setting(data):# Attributes (PutAttributes / DeleteAttributes / ListAttributes)# ----------------------------------------------------------------------------_attributes: dict = {}+_attributes = AccountScopedDict()def _put_attributes(data):attrs = data.get("attributes", [])diff --git a/ministack/services/efs.py b/ministack/services/efs.pyindex 34168a99..82c2db2c 100644--- a/ministack/services/efs.py+++ b/ministack/services/efs.py@@ -25,7 +25,7 @@ import stringimport timefrom ministack.core.persistence import PERSIST_STATE, load_state-from ministack.core.responses import get_account_id+from ministack.core.responses import AccountScopedDict, get_account_idlogger = logging.getLogger("efs")@@ -35,9 +35,9 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")# State# ----------------------------------------------------------------------------_file_systems: dict = {} # fs_id -> fs record-_mount_targets: dict = {} # mt_id -> mount target record-_access_points: dict = {} # ap_id -> access point record+_file_systems = AccountScopedDict() # fs_id -> fs record+_mount_targets = AccountScopedDict() # mt_id -> mount target record+_access_points = AccountScopedDict() # ap_id -> access point record# ---------------------------------------------------------------------------# ID generators@@ -334,8 +334,8 @@ def _find_resource(resource_id):# Lifecycle / Backup / Account (stubs)# ----------------------------------------------------------------------------_lifecycle_configs: dict = {}-_backup_policies: dict = {}+_lifecycle_configs = AccountScopedDict()+_backup_policies = AccountScopedDict()def get_state():diff --git a/ministack/services/elasticache.py b/ministack/services/elasticache.pyindex ac462d1b..b60e1f00 100644--- a/ministack/services/elasticache.py+++ b/ministack/services/elasticache.py@@ -27,7 +27,7 @@ import timefrom urllib.parse import parse_qsfrom ministack.core.persistence import load_state-from ministack.core.responses import get_account_id, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, new_uuidlogger = logging.getLogger("elasticache")@@ -36,15 +36,15 @@ REDIS_DEFAULT_HOST = os.environ.get("REDIS_HOST", "redis")REDIS_DEFAULT_PORT = int(os.environ.get("REDIS_PORT", "6379"))BASE_PORT = int(os.environ.get("ELASTICACHE_BASE_PORT", "16379"))-_clusters: dict = {}-_replication_groups: dict = {}-_subnet_groups: dict = {}-_param_groups: dict = {}-_param_group_params: dict = {} # group_name -> {param_name -> param_dict}-_tags: dict = {} # arn -> [{"Key": ..., "Value": ...}, ...]-_snapshots: dict = {}-_users: dict = {}-_user_groups: dict = {}+_clusters = AccountScopedDict()+_replication_groups = AccountScopedDict()+_subnet_groups = AccountScopedDict()+_param_groups = AccountScopedDict()+_param_group_params = AccountScopedDict() # group_name -> {param_name -> param_dict}+_tags = AccountScopedDict() # arn -> [{"Key": ..., "Value": ...}, ...]+_snapshots = AccountScopedDict()+_users = AccountScopedDict()+_user_groups = AccountScopedDict()_events: list = []_port_counter = [BASE_PORT]diff --git a/ministack/services/emr.py b/ministack/services/emr.pyindex cfbc1b8c..4db3a837 100644--- a/ministack/services/emr.py+++ b/ministack/services/emr.py@@ -23,7 +23,7 @@ import stringimport timefrom ministack.core.persistence import PERSIST_STATE, load_state-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuidlogger = logging.getLogger("emr")@@ -33,8 +33,8 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")# State# ----------------------------------------------------------------------------_clusters: dict = {} # cluster_id -> cluster record-_steps: dict = {} # cluster_id -> [step records]+_clusters = AccountScopedDict() # cluster_id -> cluster record+_steps = AccountScopedDict() # cluster_id -> [step records]_block_public_access: dict = {"BlockPublicSecurityGroupRules": False,"PermittedPublicSecurityGroupRuleRanges": [],diff --git a/ministack/services/eventbridge.py b/ministack/services/eventbridge.pyindex cf3e24f4..4d80ba7b 100644--- a/ministack/services/eventbridge.py+++ b/ministack/services/eventbridge.py@@ -23,7 +23,7 @@ import threadingimport timefrom datetime import datetime-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuidlogger = logging.getLogger("events")@@ -58,14 +58,14 @@ _event_buses: dict = {"LastModifiedTime": _now_ts(),}}-_rules: dict = {}-_targets: dict = {}+_rules = AccountScopedDict()+_targets = AccountScopedDict()_events_log: list = []-_tags: dict = {}-_archives: dict = {}-_event_bus_policies: dict = {} # bus_name -> {Statement: [...]}-_connections: dict = {} # connection_name -> {...}-_api_destinations: dict = {} # destination_name -> {...}+_tags = AccountScopedDict()+_archives = AccountScopedDict()+_event_bus_policies = AccountScopedDict() # bus_name -> {Statement: [...]}+_connections = AccountScopedDict() # connection_name -> {...}+_api_destinations = AccountScopedDict() # destination_name -> {...}# ── Persistence ────────────────────────────────────────────diff --git a/ministack/services/firehose.py b/ministack/services/firehose.pyindex 964298d0..bbcdb5d7 100644--- a/ministack/services/firehose.py+++ b/ministack/services/firehose.py@@ -25,6 +25,7 @@ import timefrom ministack.core.persistence import PERSIST_STATE, load_statefrom ministack.core.responses import (+ AccountScopedDict,get_account_id,error_response_json,json_response,@@ -38,7 +39,7 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")# ─── in-memory state ──────────────────────────────────────────────────────────-_streams: dict = {} # name -> stream descriptor+_streams = AccountScopedDict() # name -> stream descriptor_lock = threading.Lock()_dest_counter = 0diff --git a/ministack/services/glue.py b/ministack/services/glue.pyindex 47a391cf..fef4a3ec 100644--- a/ministack/services/glue.py+++ b/ministack/services/glue.py@@ -19,7 +19,7 @@ import threadingimport timefrom ministack.core.persistence import PERSIST_STATE, load_state-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuidlogger = logging.getLogger("glue")@@ -27,20 +27,20 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")CRAWLER_RUN_SECONDS = int(os.environ.get("GLUE_CRAWLER_RUN_SECONDS", "5"))S3_DATA_DIR = os.environ.get("S3_DATA_DIR", "/tmp/ministack-data/s3")-_databases: dict = {}-_tables: dict = {} # "db_name/table_name" -> table dict-_partitions: dict = {} # "db_name/table_name" -> [partition, ...]-_partition_indexes: dict = {} # "db_name/table_name" -> [index, ...]-_connections: dict = {}-_crawlers: dict = {}-_jobs: dict = {}-_job_runs: dict = {} # job_name -> [run, ...]-_tags: dict = {} # arn -> {key: value, ...}-_security_configs: dict = {}-_classifiers: dict = {}-_triggers: dict = {} # trigger_name -> trigger dict-_workflows: dict = {} # workflow_name -> workflow dict-_workflow_runs: dict = {} # workflow_name -> [run, ...]+_databases = AccountScopedDict()+_tables = AccountScopedDict() # "db_name/table_name" -> table dict+_partitions = AccountScopedDict() # "db_name/table_name" -> [partition, ...]+_partition_indexes = AccountScopedDict() # "db_name/table_name" -> [index, ...]+_connections = AccountScopedDict()+_crawlers = AccountScopedDict()+_jobs = AccountScopedDict()+_job_runs = AccountScopedDict() # job_name -> [run, ...]+_tags = AccountScopedDict() # arn -> {key: value, ...}+_security_configs = AccountScopedDict()+_classifiers = AccountScopedDict()+_triggers = AccountScopedDict() # trigger_name -> trigger dict+_workflows = AccountScopedDict() # workflow_name -> workflow dict+_workflow_runs = AccountScopedDict() # workflow_name -> [run, ...]_ALL_STATE = {"databases": _databases,diff --git a/ministack/services/iam_sts.py b/ministack/services/iam_sts.pyindex 2670a3db..66b23241 100644--- a/ministack/services/iam_sts.py+++ b/ministack/services/iam_sts.py@@ -36,7 +36,7 @@ import timefrom urllib.parse import parse_qsfrom urllib.parse import quote as _url_quote-from ministack.core.responses import get_account_id, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, json_response, new_uuidlogger = logging.getLogger("iam")@@ -47,15 +47,15 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")# ---------------------------------------------------------------------------from ministack.core.persistence import load_state, PERSIST_STATE-_users: dict = {}-_roles: dict = {}-_policies: dict = {}-_access_keys: dict = {}-_instance_profiles: dict = {}-_groups: dict = {}-_user_inline_policies: dict = {}-_oidc_providers: dict = {}-_service_linked_role_deletion_tasks: dict = {}+_users = AccountScopedDict()+_roles = AccountScopedDict()+_policies = AccountScopedDict()+_access_keys = AccountScopedDict()+_instance_profiles = AccountScopedDict()+_groups = AccountScopedDict()+_user_inline_policies = AccountScopedDict()+_oidc_providers = AccountScopedDict()+_service_linked_role_deletion_tasks = AccountScopedDict()# ── Persistence ────────────────────────────────────────────diff --git a/ministack/services/kinesis.py b/ministack/services/kinesis.pyindex dd7c4ced..54264794 100644--- a/ministack/services/kinesis.py+++ b/ministack/services/kinesis.py@@ -21,7 +21,7 @@ import loggingimport threadingimport time-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuidlogger = logging.getLogger("kinesis")@@ -31,9 +31,9 @@ ITERATOR_EXPIRY_SECONDS = 300from ministack.core.persistence import load_state, PERSIST_STATE-_streams: dict = {}-_shard_iterators: dict = {}-_consumers: dict = {}+_streams = AccountScopedDict()+_shard_iterators = AccountScopedDict()+_consumers = AccountScopedDict()_sequence_counter = 0_sequence_lock = threading.Lock()diff --git a/ministack/services/kms.py b/ministack/services/kms.pyindex 45244f62..70c5d38c 100644--- a/ministack/services/kms.py+++ b/ministack/services/kms.py@@ -13,7 +13,7 @@ import loggingimport osimport time-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuidlogger = logging.getLogger("kms")@@ -35,7 +35,7 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")from ministack.core.persistence import load_state, PERSIST_STATE-_keys: dict = {}+_keys = AccountScopedDict()# key_id -> {# KeyId, Arn, KeyState, KeyUsage, KeySpec, Description,# CreationDate, Enabled, Origin,@@ -43,7 +43,7 @@ _keys: dict = {}# _public_key_der (bytes, RSA only),# _symmetric_key (bytes, SYMMETRIC_DEFAULT only),# }-_aliases: dict = {} # alias_name -> key_id (e.g. "alias/my-key" -> "uuid")+_aliases = AccountScopedDict() # alias_name -> key_id (e.g. "alias/my-key" -> "uuid")# ── Persistence ────────────────────────────────────────────diff --git a/ministack/services/lambda_svc.py b/ministack/services/lambda_svc.pyindex 965528c7..1eb4f88a 100644--- a/ministack/services/lambda_svc.py+++ b/ministack/services/lambda_svc.py@@ -43,7 +43,7 @@ from typing import Anyfrom urllib.parse import unquotefrom ministack.core.persistence import load_state, PERSIST_STATE-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuidfrom ministack.core.lambda_runtime import get_or_create_worker, invalidate_workerlogger = logging.getLogger("lambda")@@ -60,10 +60,10 @@ except ImportError:docker_lib = None_docker_available = False-_functions: dict = {} # function_name -> FunctionRecord-_layers: dict = {} # layer_name -> {"versions": [...], "next_version": int}-_esms: dict = {} # uuid -> esm dict-_function_urls: dict = {} # function_name -> FunctionUrlConfig dict+_functions = AccountScopedDict() # function_name -> FunctionRecord+_layers = AccountScopedDict() # layer_name -> {"versions": [...], "next_version": int}+_esms = AccountScopedDict() # uuid -> esm dict+_function_urls = AccountScopedDict() # function_name -> FunctionUrlConfig dict_poller_started = False_poller_lock = threading.Lock()@@ -2455,9 +2455,9 @@ def _delete_esm(esm_id: str):# ---------------------------------------------------------------------------# Per-ESM Kinesis iterator tracking: esm_uuid -> {shard_id: position}-_kinesis_positions: dict = {}+_kinesis_positions = AccountScopedDict()# Per-ESM DynamoDB stream tracking: esm_uuid -> {shard_id: position}-_dynamodb_stream_positions: dict = {}+_dynamodb_stream_positions = AccountScopedDict()_dynamodb_stream_positions_lock = threading.Lock()diff --git a/ministack/services/rds.py b/ministack/services/rds.pyindex 5e1f41d7..5cbb1648 100644--- a/ministack/services/rds.py+++ b/ministack/services/rds.py@@ -32,7 +32,7 @@ from urllib.parse import parse_qsfrom xml.sax.saxutils import escape as _escfrom ministack.core.persistence import load_state-from ministack.core.responses import get_account_id, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, new_uuidlogger = logging.getLogger("rds")@@ -40,16 +40,16 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")BASE_PORT = int(os.environ.get("RDS_BASE_PORT", "15432"))RDS_TMPFS_SIZE = os.environ.get("RDS_TMPFS_SIZE", "256m")-_instances: dict = {}-_clusters: dict = {}-_subnet_groups: dict = {}-_param_groups: dict = {}-_snapshots: dict = {}-_db_cluster_param_groups: dict = {}-_db_cluster_snapshots: dict = {}-_option_groups: dict = {}-_global_clusters: dict = {}-_tags: dict = {}+_instances = AccountScopedDict()+_clusters = AccountScopedDict()+_subnet_groups = AccountScopedDict()+_param_groups = AccountScopedDict()+_snapshots = AccountScopedDict()+_db_cluster_param_groups = AccountScopedDict()+_db_cluster_snapshots = AccountScopedDict()+_option_groups = AccountScopedDict()+_global_clusters = AccountScopedDict()+_tags = AccountScopedDict()_port_counter = [BASE_PORT]_docker = Nonediff --git a/ministack/services/rds_data.py b/ministack/services/rds_data.pyindex 7c7d2fe7..102f1035 100644--- a/ministack/services/rds_data.py+++ b/ministack/services/rds_data.py@@ -10,7 +10,7 @@ import osimport threadingimport uuid-from ministack.core.responses import get_account_id, error_response_json, json_response+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_responselogger = logging.getLogger("rds-data")diff --git a/ministack/services/route53.py b/ministack/services/route53.pyindex a3310b21..c1af05a1 100644--- a/ministack/services/route53.py+++ b/ministack/services/route53.py@@ -29,7 +29,7 @@ from defusedxml.ElementTree import fromstringfrom xml.etree.ElementTree import Element, SubElement, tostringfrom ministack.core.persistence import load_state, PERSIST_STATE-from ministack.core.responses import new_uuid+from ministack.core.responses import AccountScopedDict, new_uuidlogger = logging.getLogger("route53")@@ -38,13 +38,13 @@ API_VERSION = "2013-04-01"# ─── in-memory state ──────────────────────────────────────────────────────────-_zones: dict = {} # zone_id -> zone dict-_records: dict = {} # zone_id -> list of record-set dicts-_changes: dict = {} # change_id -> change dict-_health_checks: dict = {} # hc_id -> health check dict-_tags: dict = {} # (resource_type, resource_id) -> {key: value}-_caller_refs: dict = {} # caller_reference -> zone_id (idempotency)-_hc_caller_refs: dict = {} # caller_reference -> hc_id+_zones = AccountScopedDict() # zone_id -> zone dict+_records = AccountScopedDict() # zone_id -> list of record-set dicts+_changes = AccountScopedDict() # change_id -> change dict+_health_checks = AccountScopedDict() # hc_id -> health check dict+_tags = AccountScopedDict() # (resource_type, resource_id) -> {key: value}+_caller_refs = AccountScopedDict() # caller_reference -> zone_id (idempotency)+_hc_caller_refs = AccountScopedDict() # caller_reference -> hc_id_lock = threading.Lock()diff --git a/ministack/services/s3.py b/ministack/services/s3.pyindex 01ae11d3..59cb6d16 100644--- a/ministack/services/s3.py+++ b/ministack/services/s3.py@@ -38,6 +38,7 @@ from xml.etree.ElementTree import Element, SubElement, tostringfrom ministack.core.persistence import load_state, PERSIST_STATEfrom ministack.core.responses import (+ AccountScopedDict,get_account_id,md5_hash,sha256_hash,@@ -54,29 +55,29 @@ XML_DECL = b'<?xml version="1.0" encoding="UTF-8"?>'# ---------------------------------------------------------------------------# In-memory storage# ----------------------------------------------------------------------------_buckets: dict = {}--_bucket_policies: dict = {}-_bucket_notifications: dict = {}-_bucket_tags: dict = {}-_bucket_versioning: dict = {}-_bucket_encryption: dict = {}-_bucket_lifecycle: dict = {}-_bucket_cors: dict = {}-_bucket_acl: dict = {}-_bucket_websites: dict = {}-_bucket_logging_config: dict = {}-_bucket_accelerate_config: dict = {}-_bucket_request_payment_config: dict = {}--_object_tags: dict = {}--_bucket_object_lock: dict = {}-_bucket_replication: dict = {}-_object_retention: dict = {}-_object_legal_hold: dict = {}--_multipart_uploads: dict = {}+_buckets = AccountScopedDict()++_bucket_policies = AccountScopedDict()+_bucket_notifications = AccountScopedDict()+_bucket_tags = AccountScopedDict()+_bucket_versioning = AccountScopedDict()+_bucket_encryption = AccountScopedDict()+_bucket_lifecycle = AccountScopedDict()+_bucket_cors = AccountScopedDict()+_bucket_acl = AccountScopedDict()+_bucket_websites = AccountScopedDict()+_bucket_logging_config = AccountScopedDict()+_bucket_accelerate_config = AccountScopedDict()+_bucket_request_payment_config = AccountScopedDict()++_object_tags = AccountScopedDict()++_bucket_object_lock = AccountScopedDict()+_bucket_replication = AccountScopedDict()+_object_retention = AccountScopedDict()+_object_legal_hold = AccountScopedDict()++_multipart_uploads = AccountScopedDict()# ── Persistence (metadata only — object bodies are NOT persisted here) ────diff --git a/ministack/services/s3files.py b/ministack/services/s3files.pyindex 8e1078f5..8576e980 100644--- a/ministack/services/s3files.py+++ b/ministack/services/s3files.py@@ -19,18 +19,18 @@ import osimport timefrom ministack.core.persistence import PERSIST_STATE, load_state-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuidlogger = logging.getLogger("s3files")REGION = os.environ.get("MINISTACK_REGION", "us-east-1")-_file_systems: dict = {}-_mount_targets: dict = {}-_access_points: dict = {}-_policies: dict = {}-_sync_configs: dict = {}-_tags: dict = {}+_file_systems = AccountScopedDict()+_mount_targets = AccountScopedDict()+_access_points = AccountScopedDict()+_policies = AccountScopedDict()+_sync_configs = AccountScopedDict()+_tags = AccountScopedDict()def get_state():diff --git a/ministack/services/secretsmanager.py b/ministack/services/secretsmanager.pyindex 9affc67e..50e3bf2a 100644--- a/ministack/services/secretsmanager.py+++ b/ministack/services/secretsmanager.py@@ -19,7 +19,7 @@ import secrets as stdlib_secretsimport stringimport time-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuidlogger = logging.getLogger("secretsmanager")@@ -27,8 +27,8 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")from ministack.core.persistence import load_state, PERSIST_STATE-_secrets: dict = {}-_resource_policies: dict = {}+_secrets = AccountScopedDict()+_resource_policies = AccountScopedDict()# name -> {# ARN, Name, Description, Tags: [{Key, Value}],# CreatedDate, LastChangedDate, LastAccessedDate,diff --git a/ministack/services/servicediscovery.py b/ministack/services/servicediscovery.pyindex 11ffcef4..51d0620a 100644--- a/ministack/services/servicediscovery.py+++ b/ministack/services/servicediscovery.py@@ -10,7 +10,7 @@ import osimport timeimport xml.etree.ElementTree as ET-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuidfrom ministack.services import route53logger = logging.getLogger("servicediscovery")@@ -18,14 +18,14 @@ logger = logging.getLogger("servicediscovery")REGION = os.environ.get("MINISTACK_REGION", "us-east-1")# In-memory state-_namespaces: dict = {} # ns_id -> namespace dict-_services: dict = {} # svc_id -> service dict-_instances: dict = {} # svc_id -> {instance_id -> instance dict}-_operations: dict = {} # op_id -> operation dict-_resource_tags: dict = {} # resource_arn -> [{"Key": ..., "Value": ...}]-_service_attributes: dict = {} # svc_id -> {key: value}-_instance_health_status: dict = {} # svc_id -> {instance_id: status}-_instances_revision: dict = {} # svc_id -> int+_namespaces = AccountScopedDict() # ns_id -> namespace dict+_services = AccountScopedDict() # svc_id -> service dict+_instances = AccountScopedDict() # svc_id -> {instance_id -> instance dict}+_operations = AccountScopedDict() # op_id -> operation dict+_resource_tags = AccountScopedDict() # resource_arn -> [{"Key": ..., "Value": ...}]+_service_attributes = AccountScopedDict() # svc_id -> {key: value}+_instance_health_status = AccountScopedDict() # svc_id -> {instance_id: status}+_instances_revision = AccountScopedDict() # svc_id -> intdef get_state():diff --git a/ministack/services/ses.py b/ministack/services/ses.pyindex db5f2c65..f91624fa 100644--- a/ministack/services/ses.py+++ b/ministack/services/ses.py@@ -39,16 +39,16 @@ from email.policy import default as default_policyfrom urllib.parse import parse_qs, unquotefrom ministack.core.persistence import PERSIST_STATE, load_state-from ministack.core.responses import get_account_id, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, new_uuidlogger = logging.getLogger("ses")REGION = os.environ.get("MINISTACK_REGION", "us-east-1")-_identities: dict = {}+_identities = AccountScopedDict()_sent_emails: list = []-_templates: dict = {}-_configuration_sets: dict = {}+_templates = AccountScopedDict()+_configuration_sets = AccountScopedDict()# ---------------------------------------------------------------------------diff --git a/ministack/services/ses_v2.py b/ministack/services/ses_v2.pyindex 4b7e2f86..569962c6 100644--- a/ministack/services/ses_v2.py+++ b/ministack/services/ses_v2.py@@ -15,16 +15,16 @@ import osimport refrom ministack.core.persistence import PERSIST_STATE, load_state-from ministack.core.responses import get_account_id, json_response, new_uuid, now_iso+from ministack.core.responses import AccountScopedDict, get_account_id, json_response, new_uuid, now_isofrom ministack.services.ses import _build_mime_message, _smtp_relaylogger = logging.getLogger("ses-v2")REGION = os.environ.get("MINISTACK_REGION", "us-east-1")-_identities: dict = {} # identity -> dict-_config_sets: dict = {} # name -> dict-_ses_tags: dict = {} # resource_arn -> [tags]+_identities = AccountScopedDict() # identity -> dict+_config_sets = AccountScopedDict() # name -> dict+_ses_tags = AccountScopedDict() # resource_arn -> [tags]def get_state() -> dict:diff --git a/ministack/services/sns.py b/ministack/services/sns.pyindex 89be586e..f13c3a82 100644--- a/ministack/services/sns.py+++ b/ministack/services/sns.py@@ -24,7 +24,7 @@ _HOST = os.environ.get("MINISTACK_HOST", "localhost")_PORT = os.environ.get("GATEWAY_PORT", "4566")import ministack.services.lambda_svc as _lambda_svc-from ministack.core.responses import get_account_id, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, new_uuidfrom ministack.services import sqs as _sqslogger = logging.getLogger("sns")@@ -33,10 +33,10 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")from ministack.core.persistence import load_state, PERSIST_STATE-_topics: dict = {}-_sub_arn_to_topic: dict = {}-_platform_applications: dict = {}-_platform_endpoints: dict = {}+_topics = AccountScopedDict()+_sub_arn_to_topic = AccountScopedDict()+_platform_applications = AccountScopedDict()+_platform_endpoints = AccountScopedDict()# ── Persistence ────────────────────────────────────────────diff --git a/ministack/services/sqs.py b/ministack/services/sqs.pyindex 6ed9ac5e..b4fae2b2 100644--- a/ministack/services/sqs.py+++ b/ministack/services/sqs.py@@ -35,14 +35,14 @@ from urllib.parse import parse_qsfrom xml.sax.saxutils import escape as _escfrom ministack.core.persistence import load_state, PERSIST_STATE-from ministack.core.responses import get_account_id, md5_hash, new_uuid, now_iso+from ministack.core.responses import AccountScopedDict, get_account_id, md5_hash, new_uuid, now_isologger = logging.getLogger("sqs")# ── Module-level state ──────────────────────────────────────-_queues: dict = {}-_queue_name_to_url: dict = {}+_queues = AccountScopedDict()+_queue_name_to_url = AccountScopedDict()_queues_lock = threading.Lock()@@ -203,6 +203,11 @@ def _act_create_queue(data: dict, _u: str) -> dict:for k, v in attrs.items():q["attributes"][k] = str(v)+ # Apply tags passed at creation time+ create_tags = data.get("Tags") or data.get("tags") or {}+ if create_tags:+ q["tags"].update(create_tags)+_queues[url] = q_queue_name_to_url[name] = urlreturn {"QueueUrl": url}diff --git a/ministack/services/ssm.py b/ministack/services/ssm.pyindex 7fd99066..8a0dd22b 100644--- a/ministack/services/ssm.py+++ b/ministack/services/ssm.py@@ -15,7 +15,7 @@ import loggingimport timefrom datetime import datetime, timezone-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuidlogger = logging.getLogger("ssm")@@ -24,9 +24,9 @@ DEFAULT_PAGE_SIZE = 10from ministack.core.persistence import load_state, PERSIST_STATE-_parameters: dict = {}-_parameter_history: dict = {}-_tags: dict = {}+_parameters = AccountScopedDict()+_parameter_history = AccountScopedDict()+_tags = AccountScopedDict()# ── Persistence ────────────────────────────────────────────diff --git a/ministack/services/stepfunctions.py b/ministack/services/stepfunctions.pyindex e505518f..1bd57a9c 100644--- a/ministack/services/stepfunctions.py+++ b/ministack/services/stepfunctions.py@@ -32,6 +32,7 @@ from datetime import datetime, timezonefrom ministack.core.persistence import PERSIST_STATE, load_statefrom ministack.core.responses import (+ AccountScopedDict,get_account_id,error_response_json,json_response,@@ -44,7 +45,7 @@ logger = logging.getLogger("states")REGION = os.environ.get("MINISTACK_REGION", "us-east-1")# SFN mock config — compatible with LocalStack's SFN_MOCK_CONFIG / LOCALSTACK_SFN_MOCK_CONFIG-_sfn_mock_config: dict = {}+_sfn_mock_config = AccountScopedDict()_sfn_mock_config_path = (os.environ.get("SFN_MOCK_CONFIG")or os.environ.get("LOCALSTACK_SFN_MOCK_CONFIG")@@ -91,12 +92,12 @@ def _get_mock_response(sm_name: str, test_case: str, state_name: str, attempt: icontinuereturn None-_state_machines: dict = {}-_executions: dict = {}-_task_tokens: dict = {}-_tags: dict = {}-_activities: dict = {}-_activity_tasks: dict = {}+_state_machines = AccountScopedDict()+_executions = AccountScopedDict()+_task_tokens = AccountScopedDict()+_tags = AccountScopedDict()+_activities = AccountScopedDict()+_activity_tasks = AccountScopedDict()# ── Persistence ────────────────────────────────────────────diff --git a/ministack/services/waf.py b/ministack/services/waf.pyindex 4c9d224f..a5f0c2de 100644--- a/ministack/services/waf.py+++ b/ministack/services/waf.py@@ -15,17 +15,17 @@ import osimport loggingfrom ministack.core.persistence import PERSIST_STATE, load_state-from ministack.core.responses import get_account_id, error_response_json, json_response, new_uuid, now_iso+from ministack.core.responses import AccountScopedDict, get_account_id, error_response_json, json_response, new_uuid, now_isologger = logging.getLogger("wafv2")REGION = os.environ.get("MINISTACK_REGION", "us-east-1")-_web_acls: dict = {} # id -> webacl-_ip_sets: dict = {} # id -> ipset-_rule_groups: dict = {} # id -> rulegroup-_associations: dict = {} # resource_arn -> webacl_arn-_waf_tags: dict = {} # resource_arn -> [tags]+_web_acls = AccountScopedDict() # id -> webacl+_ip_sets = AccountScopedDict() # id -> ipset+_rule_groups = AccountScopedDict() # id -> rulegroup+_associations = AccountScopedDict() # resource_arn -> webacl_arn+_waf_tags = AccountScopedDict() # resource_arn -> [tags]def get_state():diff --git a/pyproject.toml b/pyproject.tomlindex 548a45a5..e4e2dded 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"[project]name = "ministack"-version = "1.1.55"+version = "1.1.56"description = "Free, open-source local AWS emulator — drop-in LocalStack replacement"readme = "README.md"license = { file = "LICENSE" }