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
release v1.3.23 (#539)
Nahuel Nucera18f41754f3d2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fe7179e6..91b5c8f9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,10 +7,29 @@ Versioning follows [Semantic Versioning](https://semver.org/).----## [Unreleased]+## [1.3.23] — 2026-05-01### Added-- **EventBridge scheduled rule auto-fire** — `rate(N minute|hour|day)` rules now fire automatically in Ministack. A background daemon thread (`eb-scheduler`) ticks every 10 seconds and dispatches enabled rules whose interval has elapsed. Follows the AWS-documented behaviour: the countdown starts at rule creation time so the first fire is one full interval after the rule is enabled, not immediately. The scheduled event payload matches the AWS wire format exactly: `"source": "aws.events"`, `"detail-type": "Scheduled Event"`, `"detail": {}`, `"version": "0"`, `"resources": [rule_arn]`, and `"time"` as an ISO 8601 UTC string. Iterates `_rules._data` directly so multi-tenant (multi-account) setups work correctly. `cron()` expressions are accepted and stored but not yet auto-fired. `reset()` clears the scheduler state. 12 unit tests cover rate-expression parsing and all tick-decision branches; one slow end-to-end integration test (gated by `MINISTACK_SLOW_TESTS=1`) exercises the full path from `PutRule`/`PutTargets` through Lambda invocation.++- **Amazon OpenSearch Service** — management plane on `/2021-01-01/*`: CreateDomain, DescribeDomain(s), DeleteDomain, ListDomainNames (with `EngineType` filter), UpdateDomainConfig, DescribeDomainConfig (`Options`/`Status` wrapping), DescribeDomainChangeProgress, ListVersions, GetCompatibleVersions, AddTags/ListTags/RemoveTags. Account-scoped state. Default data plane is a stub endpoint; set `OPENSEARCH_DATAPLANE=1` to spawn one real `opensearchproject/opensearch` container per `CreateDomain` (same pattern as ElastiCache/RDS). Add `OPENSEARCH_DASHBOARDS=1` for an optional per-domain `opensearch-dashboards` sidecar — `DescribeDomain.DashboardEndpoint` is populated. `DeleteDomain` tears down spawned containers. Terraform `aws_opensearch_domain` compatible. Requested by @marcin-nowak-scl.+- **EventBridge scheduled rule auto-fire** — `rate(N minute|hour|day)` rules now fire automatically. A daemon thread (`eb-scheduler`) ticks every 10 s; the per-rule countdown anchors to `CreationTime` so the first fire lands one full interval after `PutRule`. Scheduled event payload matches AWS exactly (`source: aws.events`, `detail-type: Scheduled Event`, `detail: {}`, ISO 8601 `time`). Multi-tenant — iterates the rules store directly. `cron()` expressions are stored but not yet auto-fired (one-time `INFO` log surfaces the gap). Contributed by @hiddengearz.+- **AWS Organizations** — DescribeOrganization, ListRoots, ListAccounts, DescribeAccount, ListOrganizationalUnitsForParent / ListAccountsForParent, CreateOrganizationalUnit / DescribeOrganizationalUnit / DeleteOrganizationalUnit. Single-master-account org auto-initialised on first call; nested OUs carry the new `Path` field (2026-03 AWS additive change).+- **AWS Account service** — GetAccountInformation, GetContactInformation, ListRegions, GetRegionOptStatus. Returns the new `AccountState: ACTIVE` field (2026-04 AWS additive change). Older boto3 SDKs strip the field; newer ones see it.+- **AWS Batch** — control-plane stub: ComputeEnvironments, JobQueues, JobDefinitions (auto-revisioning), SubmitJob (auto-`SUCCEEDED`), DescribeJobs, ListJobs. Account-scoped.+- **WAF Classic + Regional (v1)** — minimal stub so legacy clients (Terraform, old CFN) get clean empty-state responses instead of 405. `List*` returns empty arrays, `GetChangeToken`/`GetChangeTokenStatus` return valid responses, `Get*` for unknown resources returns `WAFNonexistentItemException`. For full WebACL state use `wafv2`.+- **EC2 DescribeRegions** — returns 31 commercial regions with correct `OptInStatus` (`opt-in-not-required` for legacy us-*/eu-*/ap-* regions, `opted-in` for newer ones). Supports `RegionNames` filter and `AllRegions` toggle.+- **Lambda `FileSystemConfigs` accepts S3 ARNs** — the 2026-04 AWS S3-mount addition. Server stores and round-trips whatever ARN format the SDK sends (EFS access points, S3 buckets, future shapes).+- **EventBridge `LogConfig`** — additive 2026-03 field on `CreateEventBus` / `UpdateEventBus`; persisted, returned on `DescribeEventBus`.+- **API Gateway v1 `securityPolicy` accepts the new TLS-1.3 enum** — allow-lists `SecurityPolicy-TLS13-1-2-FIPS-PFS-PQ-2025-09` (2026-03 addition) and any future opaque values; default remains `TLS_1_2`.++### Fixed++- **S3 `PostObject` accepts unquoted `Content-Disposition` field names** — .NET's `MultipartFormDataContent` emits `name=foo` for ASCII-clean values per RFC 2183; the parser previously only matched the quoted form `name="foo"` and dropped `key`/`success_action_status`, causing browser-form uploads from .NET clients to 400. Reported by @mattburton.+- **EventBridge target dispatch `time` field is ISO 8601** — was a Unix epoch float, AWS specifies a string like `2026-05-01T18:08:16Z`. Both `PutEvents`-driven and scheduled-rule-driven dispatches now use the canonical format.++### Performance++- **Idle RAM%** — Dockerfile now sets `PYTHONOPTIMIZE=2` and `MALLOC_ARENA_MAX=2`. Verified zero correctness impact (no `assert` or `__doc__` introspection in ministack source); throughput unchanged.---diff --git a/Dockerfile b/Dockerfileindex 5e1a28ef..7a298cb9 100644--- a/Dockerfile+++ b/Dockerfile@@ -63,7 +63,9 @@ ENV MINISTACK_VERSION=${MINISTACK_VERSION} \ELASTICACHE_BASE_PORT=16379 \LAMBDA_EXECUTOR=local \USE_SSL=0 \- PYTHONUNBUFFERED=1+ PYTHONUNBUFFERED=1 \+ PYTHONOPTIMIZE=2 \+ MALLOC_ARENA_MAX=2EXPOSE 4566 2222diff --git a/Dockerfile.full b/Dockerfile.fullindex 8377dc30..ca4a3e6e 100644--- a/Dockerfile.full+++ b/Dockerfile.full@@ -78,7 +78,9 @@ ENV MINISTACK_VERSION=${MINISTACK_VERSION} \ELASTICACHE_BASE_PORT=16379 \LAMBDA_EXECUTOR=local \USE_SSL=0 \- PYTHONUNBUFFERED=1+ PYTHONUNBUFFERED=1 \+ PYTHONOPTIMIZE=2 \+ MALLOC_ARENA_MAX=2EXPOSE 4566 2222diff --git a/README.md b/README.mdindex c9ce97fe..68c513a2 100644--- a/README.md+++ b/README.md@@ -501,6 +501,11 @@ Unsupported resource types fail with `CREATE_FAILED` (or `ROLLBACK_COMPLETE` if| **Transfer Family** | CreateServer, DescribeServer, DeleteServer, ListServers, StartServer, StopServer, CreateUser, DescribeUser, DeleteUser, ListUsers, ImportSshPublicKey, DeleteSshPublicKey | 12 operations; **real SFTP listener** on `:2222` (override with `SFTP_PORT`) backed by S3 — `ls`, `put`, `get`, `mkdir`, `rename` work end-to-end against the local S3 emulator; `SFTP_PORT_PER_SERVER=1` allocates one port per `CreateServer` from `SFTP_BASE_PORT` (default 2300); SSH key auth scans every user across every server and account; `LOGICAL` and `PATH` home-directory mappings; host key persists across restarts when `PERSIST_STATE=1` || **EventBridge Scheduler** | CreateSchedule, GetSchedule, UpdateSchedule, DeleteSchedule, ListSchedules, CreateScheduleGroup, GetScheduleGroup, DeleteScheduleGroup, ListScheduleGroups, TagResource, UntagResource, ListTagsForResource | 12 actions; schedule groups with cascading deletes; `rate()`, `cron()`, `at()` expressions; group/prefix/state filters on list; default group auto-created; CFN `AWS::Scheduler::Schedule` and `AWS::Scheduler::ScheduleGroup` supported || **EKS** | CreateCluster, DescribeCluster, ListClusters, DeleteCluster, CreateNodegroup, DescribeNodegroup, ListNodegroups, DeleteNodegroup, TagResource, UntagResource, ListTagsForResource | 11 operations; `CreateCluster` spawns a real **k3s** container (75 MB) with a full Kubernetes API server; `kubectl`, Helm, and any K8s tooling work out of the box; cascading delete removes nodegroups and k3s container; CFN `AWS::EKS::Cluster` and `AWS::EKS::Nodegroup` supported |+| **OpenSearch Service** | CreateDomain, DescribeDomain, DescribeDomains, DeleteDomain, ListDomainNames, UpdateDomainConfig, DescribeDomainConfig, DescribeDomainChangeProgress, ListVersions, GetCompatibleVersions, AddTags, ListTags, RemoveTags | Management plane on `/2021-01-01/*` (`boto3.client("opensearch")`, SigV4 scope `es`). Default data plane is a stub endpoint (`<domain>.ministack.local:9200`) — set `OPENSEARCH_DATAPLANE=1` to spawn one real `opensearchproject/opensearch` container per `CreateDomain` (same pattern as ElastiCache/RDS); `DescribeDomain.Endpoint` then points at that container and `_cluster/health`/`/_search` work end-to-end. Add `OPENSEARCH_DASHBOARDS=1` (with dataplane on) to also spawn a per-domain `opensearch-dashboards` sidecar; `DescribeDomain.DashboardEndpoint` is populated. ARNs follow `arn:aws:es:<region>:<account>:domain/<name>`; Terraform `aws_opensearch_domain` resource compatible. |+| **Organizations** | DescribeOrganization, ListRoots, ListAccounts, ListAccountsForParent, DescribeAccount, CreateOrganizationalUnit, DescribeOrganizationalUnit, DeleteOrganizationalUnit, ListOrganizationalUnitsForParent | Single-master-account org auto-initialised on first call; nested OUs with `Path` field (additive 2026-03 AWS change); `FeatureSet=ALL` |+| **Account** | GetAccountInformation, GetContactInformation, ListRegions, GetRegionOptStatus | rest-json `/getAccountInformation`, etc.; returns `AccountState=ACTIVE` (additive 2026-04 AWS change); 31-region opt-in matrix |+| **WAF (Classic + Regional)** | List* (17 ops), Get*, GetChangeToken, GetChangeTokenStatus, GetPermissionPolicy, Create*/Update*/Delete* (stubbed) | Minimal v1 stub — empty lists for all `List*`, valid ChangeToken on Create/Update/Delete; for full features use **wafv2** (also supported) |+| **Batch** | CreateComputeEnvironment, DescribeComputeEnvironments, CreateJobQueue, DescribeJobQueues, RegisterJobDefinition, DescribeJobDefinitions, SubmitJob, DescribeJobs, ListJobs | Control-plane stub — submitted jobs immediately transition to `SUCCEEDED`; multi-revision job definitions; `jobQueue` lookup by name or ARN; account-scoped state |---@@ -648,6 +653,13 @@ ecs.stop_task(cluster="dev", task=task_arn)| `DOCKER_NETWORK` | _(unset)_ | Docker network for all container-backed services (RDS, EKS, ElastiCache, Lambda). Set to your Docker Compose network name so containers can reach each other. Replaces `LAMBDA_DOCKER_NETWORK` || `ELASTICACHE_BASE_PORT` | `16379` | Starting host port for ElastiCache containers || `ELASTICACHE_CLUSTER_MODE_REAL` | `0` | Set `1` (requires `DOCKER_NETWORK`) to provision real Redis Cluster replication groups: `NumNodeGroups × (1+ReplicasPerNodeGroup)` cluster-enabled nodes wired with `redis-cli --cluster create`, serving real `CLUSTER SLOTS` / `MOVED` redirects for cluster-aware clients |+| `OPENSEARCH_DATAPLANE` | `0` | Set `1` to spawn a real `opensearchproject/opensearch` container per `CreateDomain`. Default `0` returns a stub endpoint (`<domain>.ministack.local:9200`) — management plane only |+| `OPENSEARCH_BASE_PORT` | `14571` | Starting host port for per-domain OpenSearch containers when `OPENSEARCH_DATAPLANE=1` |+| `OPENSEARCH_IMAGE` | `opensearchproject/opensearch:2.15.0` | Image used when spawning per-domain OpenSearch containers |+| `OPENSEARCH_DASHBOARDS` | `0` | Set `1` (together with `OPENSEARCH_DATAPLANE=1`) to also spawn a per-domain `opensearchproject/opensearch-dashboards` sidecar; `DescribeDomain.DashboardEndpoint` is populated |+| `OPENSEARCH_DASHBOARDS_BASE_PORT` | `15601` | Starting host port for per-domain Dashboards containers |+| `OPENSEARCH_DASHBOARDS_IMAGE` | `opensearchproject/opensearch-dashboards:2.15.0` | Image used when spawning per-domain Dashboards containers |+| `MINISTACK_OPENSEARCH_ENDPOINT` | _(unset)_ | If set (e.g. `localhost:9200`), every domain returns this endpoint instead of spawning a per-domain container — useful when you bring your own cluster || `PERSIST_STATE` | `0` | Set `1` to persist service state across restarts || `STATE_DIR` | `/tmp/ministack-state` | Directory for persisted state files || `LAMBDA_EXECUTOR` | `local` | Lambda execution mode: `local` (subprocess) or `docker` (container). `provided` runtimes and `PackageType: Image` always use Docker |@@ -924,7 +936,7 @@ pip install boto3 pytest duckdb docker cbor2# Start MiniStackdocker compose up -d-# Run the full test suite (1,800+ tests across all services)+# Run the full test suite (2,100+ tests across all services)pytest tests/ -v```@@ -935,7 +947,7 @@ tests/test_s3.py::test_s3_create_bucket PASSED...tests/test_lambda.py::test_lambda_invoke PASSED-1800+ passed in ~120s+2100+ passed in ~120s```---diff --git a/ministack/app.py b/ministack/app.pyindex 2746c445..bc58bb3a 100644--- a/ministack/app.py+++ b/ministack/app.py@@ -175,8 +175,10 @@ logger = logging.getLogger("ministack")# Single source of truth for routable services, their backing modules, and aliases.SERVICE_REGISTRY = {+ "account": {"module": "account"},"acm": {"module": "acm"},"backup": {"module": "backup"},+ "batch": {"module": "batch"},"apigateway": {"module": "apigateway", "aliases": ("execute-api", "apigatewayv2")},"appconfig": {"module": "appconfig"},"appconfigdata": {"module": "appconfig"},@@ -207,6 +209,8 @@ SERVICE_REGISTRY = {"kms": {"module": "kms"},"lambda": {"module": "lambda_svc"},"logs": {"module": "cloudwatch_logs", "aliases": ("cloudwatch-logs",)},+ "opensearch": {"module": "opensearch", "aliases": ("es", "elasticsearch")},+ "organizations": {"module": "organizations"},"monitoring": {"module": "cloudwatch", "aliases": ("cloudwatch",)},"rds-data": {"module": "rds_data"},"rds": {"module": "rds"},@@ -224,6 +228,8 @@ SERVICE_REGISTRY = {"sts": {"module": "sts"},"tagging": {"module": "tagging"},"transfer": {"module": "transfer"},+ "waf": {"module": "waf_v1"},+ "waf-regional": {"module": "waf_v1"},"wafv2": {"module": "waf"},}diff --git a/ministack/core/router.py b/ministack/core/router.pyindex 24aed528..22b40d8d 100644--- a/ministack/core/router.py+++ b/ministack/core/router.py@@ -174,6 +174,42 @@ SERVICE_PATTERNS = {"host_patterns": [r"wafv2\."],"credential_scope": "wafv2",},+ "waf": {+ "target_prefixes": ["AWSWAF_20150824"],+ "host_patterns": [r"^waf\.(?!regional)"],+ "credential_scope": "waf",+ },+ "waf-regional": {+ "target_prefixes": ["AWSWAF_Regional_20161128"],+ "host_patterns": [r"waf-regional\."],+ "credential_scope": "waf-regional",+ },+ "opensearch": {+ "host_patterns": [r"^es\.", r"^aos\.", r"^opensearch\."],+ "path_prefixes": [+ "/2021-01-01/domain", "/2021-01-01/opensearch",+ "/2021-01-01/versions", "/2021-01-01/compatibleVersions",+ "/2021-01-01/tags", "/2021-01-01/tags-removal",+ ],+ "credential_scope": "es",+ },+ "organizations": {+ "target_prefixes": ["AWSOrganizationsV20161128"],+ "host_patterns": [r"^organizations\."],+ "credential_scope": "organizations",+ },+ "account": {+ "host_patterns": [r"^account\."],+ "path_prefixes": ["/getAccountInformation", "/getContactInformation",+ "/listRegions", "/getRegionOptStatus",+ "/getAlternateContact", "/getPrimaryEmail"],+ "credential_scope": "account",+ },+ "batch": {+ "host_patterns": [r"^batch\."],+ "path_prefixes": ["/v1/"],+ "credential_scope": "batch",+ },"cloudformation": {"host_patterns": [r"cloudformation\."],},@@ -289,6 +325,13 @@ def detect_service(method: str, path: str, headers: dict, query_params: dict) ->"route53": "route53","acm": "acm","wafv2": "wafv2",+ "waf": "waf",+ "waf-regional": "waf-regional",+ "es": "opensearch",+ "opensearch": "opensearch",+ "organizations": "organizations",+ "account": "account",+ "batch": "batch","cognito-idp": "cognito-idp","cognito-identity": "cognito-identity","ecr": "ecr",diff --git a/ministack/services/account.py b/ministack/services/account.pynew file mode 100644index 00000000..f33488c7--- /dev/null+++ b/ministack/services/account.py@@ -0,0 +1,121 @@+"""+AWS Account service stub (rest-json).++Endpoints (botocore service-2.json):+- POST /getAccountInformation GetAccountInformation+- POST /getContactInformation GetContactInformation+- POST /listRegions ListRegions+- POST /getRegionOptStatus GetRegionOptStatus++Includes the ``AccountState`` field added by AWS on 2026-04-29 (additive).+Older SDKs silently drop unknown response fields per JSON protocol; newer+SDKs see ``AccountState`` populated.+"""++import json+import logging+import time++from ministack.core.responses import (+ error_response_json,+ get_account_id,+)++logger = logging.getLogger("account")+++def _json(status, body):+ return status, {"Content-Type": "application/json"}, json.dumps(body).encode()+++# Single fixed creation timestamp per process — AWS returns the original+# account creation time, which doesn't change. int epoch seconds per memory.+_CREATED_AT = int(time.time()) - (365 * 24 * 3600)+++def _get_account_information(_payload):+ return _json(200, {+ "AccountId": get_account_id(),+ "AccountCreatedDate": _CREATED_AT,+ "AccountName": "MiniStack Local Account",+ # AWS additive field added 2026-04-29 — represents lifecycle phase.+ # ACTIVE is the only steady-state value for an emulated account.+ "AccountState": "ACTIVE",+ })+++def _get_contact_information(_payload):+ return _json(200, {+ "ContactInformation": {+ "FullName": "MiniStack Local",+ "AddressLine1": "1 Localhost Lane",+ "City": "Local",+ "CountryCode": "US",+ "PhoneNumber": "+10000000000",+ "PostalCode": "00000",+ }+ })+++_REGIONS_LIST = [+ "us-east-1", "us-east-2", "us-west-1", "us-west-2",+ "af-south-1", "ap-east-1", "ap-south-1", "ap-south-2",+ "ap-northeast-1", "ap-northeast-2", "ap-northeast-3",+ "ap-southeast-1", "ap-southeast-2", "ap-southeast-3",+ "ap-southeast-4", "ap-southeast-5",+ "ca-central-1", "ca-west-1",+ "eu-central-1", "eu-central-2", "eu-west-1", "eu-west-2",+ "eu-west-3", "eu-north-1", "eu-south-1", "eu-south-2",+ "il-central-1", "me-south-1", "me-central-1",+ "sa-east-1", "mx-central-1",+]+_OPT_IN_REQUIRED = {+ "af-south-1", "ap-east-1", "ap-south-2", "ap-southeast-3",+ "ap-southeast-4", "ap-southeast-5", "ca-west-1", "eu-central-2",+ "eu-south-1", "eu-south-2", "il-central-1", "me-south-1",+ "me-central-1", "mx-central-1",+}+++def _list_regions(payload):+ filter_status = payload.get("RegionOptStatusContains") or []+ out = []+ for r in _REGIONS_LIST:+ status = "ENABLED_BY_DEFAULT" if r not in _OPT_IN_REQUIRED else "ENABLED"+ if filter_status and status not in filter_status:+ continue+ out.append({"RegionName": r, "RegionOptStatus": status})+ return _json(200, {"Regions": out})+++def _get_region_opt_status(payload):+ region = payload.get("RegionName")+ if not region or region not in _REGIONS_LIST:+ return error_response_json("ResourceNotFoundException",+ f"Region not found: {region}", 400)+ status = "ENABLED_BY_DEFAULT" if region not in _OPT_IN_REQUIRED else "ENABLED"+ return _json(200, {"RegionName": region, "RegionOptStatus": status})+++_DISPATCH = {+ "/getAccountInformation": _get_account_information,+ "/getContactInformation": _get_contact_information,+ "/listRegions": _list_regions,+ "/getRegionOptStatus": _get_region_opt_status,+}+++async def handle_request(method, path, headers, body, query_params):+ if method != "POST":+ return error_response_json("InvalidRequest",+ f"Unsupported method {method}", 400)+ fn = _DISPATCH.get(path.rstrip("/"))+ if fn is None:+ return error_response_json("InvalidAction",+ f"Unsupported account path: {path}", 400)+ body_text = body.decode("utf-8") if isinstance(body, bytes) else (body or "")+ try:+ payload = json.loads(body_text) if body_text else {}+ except json.JSONDecodeError:+ return error_response_json("SerializationException", "invalid JSON body", 400)+ return fn(payload)diff --git a/ministack/services/apigateway_v1.py b/ministack/services/apigateway_v1.pyindex 658cc293..ce3d19bd 100644--- a/ministack/services/apigateway_v1.py+++ b/ministack/services/apigateway_v1.py@@ -1783,6 +1783,10 @@ def _create_domain_name(data):"regionalDomainName": f"{domain_name}.execute-api.{get_region()}.amazonaws.com","regionalHostedZoneId": "Z1UJRXOUMOOFQ8","endpointConfiguration": data.get("endpointConfiguration", {"types": ["REGIONAL"]}),+ # securityPolicy is an opaque enum at the wire level; AWS keeps adding+ # new values (e.g. SecurityPolicy-TLS13-1-2-FIPS-PFS-PQ-2025-09 in+ # 2026-03). Accept whatever the caller sends; default mirrors AWS.+ "securityPolicy": data.get("securityPolicy", "TLS_1_2"),"tags": data.get("tags", {}),}_domain_names[domain_name] = dndiff --git a/ministack/services/batch.py b/ministack/services/batch.pynew file mode 100644index 00000000..107c3400--- /dev/null+++ b/ministack/services/batch.py@@ -0,0 +1,260 @@+"""+AWS Batch stub (rest-json).++Endpoints under ``/v1/``. Stores compute environments, job queues, job+definitions, and jobs in account-scoped state. Submitted jobs immediately+transition to ``SUCCEEDED`` — Batch is a control-plane/scheduler emulator+here, not a real container runner.+"""++import copy+import json+import logging+import time++from ministack.core.responses import (+ AccountScopedDict,+ error_response_json,+ get_account_id,+ get_region,+ new_uuid,+)++logger = logging.getLogger("batch")++_compute_envs = AccountScopedDict() # name -> dict+_job_queues = AccountScopedDict() # name -> dict+_job_definitions = AccountScopedDict() # name -> [revisions]+_jobs = AccountScopedDict() # job_id -> dict+++def reset():+ _compute_envs.clear()+ _job_queues.clear()+ _job_definitions.clear()+ _jobs.clear()+++def get_state():+ return {+ "compute_envs": copy.deepcopy(_compute_envs),+ "job_queues": copy.deepcopy(_job_queues),+ "job_definitions": copy.deepcopy(_job_definitions),+ "jobs": copy.deepcopy(_jobs),+ }+++def restore_state(data):+ if not data:+ return+ for store, key in (+ (_compute_envs, "compute_envs"),+ (_job_queues, "job_queues"),+ (_job_definitions, "job_definitions"),+ (_jobs, "jobs"),+ ):+ store.clear()+ for k, v in (data.get(key) or {}).items():+ store[k] = v+++def _json(status, body):+ return status, {"Content-Type": "application/json"}, json.dumps(body).encode()+++def _ce_arn(name):+ return f"arn:aws:batch:{get_region()}:{get_account_id()}:compute-environment/{name}"+++def _jq_arn(name):+ return f"arn:aws:batch:{get_region()}:{get_account_id()}:job-queue/{name}"+++def _jd_arn(name, revision):+ return f"arn:aws:batch:{get_region()}:{get_account_id()}:job-definition/{name}:{revision}"+++def _job_arn(job_id):+ return f"arn:aws:batch:{get_region()}:{get_account_id()}:job/{job_id}"+++def _now_ms():+ return int(time.time() * 1000)+++# ─── compute environments ───────────────────────────────────────+def _create_compute_environment(p):+ name = p.get("computeEnvironmentName")+ if not name:+ return error_response_json("ClientException", "computeEnvironmentName is required", 400)+ if name in _compute_envs:+ return error_response_json("ClientException",+ f"Object already exists: {name}", 400)+ rec = {+ "computeEnvironmentName": name,+ "computeEnvironmentArn": _ce_arn(name),+ "ecsClusterArn": f"arn:aws:ecs:{get_region()}:{get_account_id()}:cluster/{name}",+ "type": p.get("type", "MANAGED"),+ "state": p.get("state", "ENABLED"),+ "status": "VALID",+ "statusReason": "ComputeEnvironment is ready",+ "computeResources": p.get("computeResources", {}),+ "serviceRole": p.get("serviceRole", ""),+ "tags": p.get("tags", {}),+ }+ _compute_envs[name] = rec+ return _json(200, {"computeEnvironmentName": name,+ "computeEnvironmentArn": rec["computeEnvironmentArn"]})+++def _describe_compute_environments(p):+ names = p.get("computeEnvironments") or []+ if names:+ out = [_compute_envs[n] for n in names if n in _compute_envs]+ else:+ out = list(_compute_envs.values())+ return _json(200, {"computeEnvironments": out})+++# ─── job queues ─────────────────────────────────────────────────+def _create_job_queue(p):+ name = p.get("jobQueueName")+ if not name:+ return error_response_json("ClientException", "jobQueueName is required", 400)+ if name in _job_queues:+ return error_response_json("ClientException",+ f"Object already exists: {name}", 400)+ rec = {+ "jobQueueName": name,+ "jobQueueArn": _jq_arn(name),+ "state": p.get("state", "ENABLED"),+ "status": "VALID",+ "statusReason": "JobQueue is ready",+ "priority": p.get("priority", 1),+ "computeEnvironmentOrder": p.get("computeEnvironmentOrder", []),+ "tags": p.get("tags", {}),+ }+ _job_queues[name] = rec+ return _json(200, {"jobQueueName": name, "jobQueueArn": rec["jobQueueArn"]})+++def _describe_job_queues(p):+ names = p.get("jobQueues") or []+ if names:+ out = []+ for n in names:+ # Accept both name and ARN per AWS behaviour.+ short = n.split("/")[-1]+ if short in _job_queues:+ out.append(_job_queues[short])+ else:+ out = list(_job_queues.values())+ return _json(200, {"jobQueues": out})+++# ─── job definitions ────────────────────────────────────────────+def _register_job_definition(p):+ name = p.get("jobDefinitionName")+ if not name:+ return error_response_json("ClientException", "jobDefinitionName is required", 400)+ revisions = _job_definitions.setdefault(name, [])+ revision = len(revisions) + 1+ rec = {+ "jobDefinitionName": name,+ "jobDefinitionArn": _jd_arn(name, revision),+ "revision": revision,+ "status": "ACTIVE",+ "type": p.get("type", "container"),+ "containerProperties": p.get("containerProperties", {}),+ "tags": p.get("tags", {}),+ }+ revisions.append(rec)+ return _json(200, {"jobDefinitionName": name,+ "jobDefinitionArn": rec["jobDefinitionArn"],+ "revision": revision})+++def _describe_job_definitions(p):+ name = p.get("jobDefinitionName")+ revs = _job_definitions.get(name, []) if name else []+ if not name:+ # all+ for n, rs in _job_definitions.items():+ revs.extend(rs)+ return _json(200, {"jobDefinitions": revs})+++# ─── jobs ───────────────────────────────────────────────────────+def _submit_job(p):+ name = p.get("jobName")+ if not name:+ return error_response_json("ClientException", "jobName is required", 400)+ job_id = new_uuid()+ now = _now_ms()+ rec = {+ "jobId": job_id,+ "jobArn": _job_arn(job_id),+ "jobName": name,+ "jobQueue": p.get("jobQueue", ""),+ "jobDefinition": p.get("jobDefinition", ""),+ "status": "SUCCEEDED",+ "statusReason": "Stub job completed immediately",+ "createdAt": now,+ "startedAt": now,+ "stoppedAt": now,+ "container": {"exitCode": 0},+ "tags": p.get("tags", {}),+ }+ _jobs[job_id] = rec+ return _json(200, {"jobId": job_id, "jobName": name, "jobArn": rec["jobArn"]})+++def _describe_jobs(p):+ ids = p.get("jobs") or []+ out = [_jobs[j] for j in ids if j in _jobs]+ return _json(200, {"jobs": out})+++def _list_jobs(p):+ queue = p.get("jobQueue", "")+ status_filter = p.get("jobStatus")+ out = []+ for j in _jobs.values():+ if queue and j.get("jobQueue") not in (queue, _jq_arn(queue.split("/")[-1])):+ continue+ if status_filter and j.get("status") != status_filter:+ continue+ out.append({+ "jobId": j["jobId"], "jobArn": j["jobArn"], "jobName": j["jobName"],+ "status": j["status"], "createdAt": j["createdAt"],+ })+ return _json(200, {"jobSummaryList": out})+++_DISPATCH = {+ "/v1/createcomputeenvironment": _create_compute_environment,+ "/v1/describecomputeenvironments": _describe_compute_environments,+ "/v1/createjobqueue": _create_job_queue,+ "/v1/describejobqueues": _describe_job_queues,+ "/v1/registerjobdefinition": _register_job_definition,+ "/v1/describejobdefinitions": _describe_job_definitions,+ "/v1/submitjob": _submit_job,+ "/v1/describejobs": _describe_jobs,+ "/v1/listjobs": _list_jobs,+}+++async def handle_request(method, path, headers, body, query_params):+ if method != "POST":+ return error_response_json("InvalidRequest",+ f"Unsupported method {method}", 400)+ fn = _DISPATCH.get(path.rstrip("/").lower())+ if fn is None:+ return error_response_json("InvalidAction",+ f"Unsupported batch path: {path}", 400)+ body_text = body.decode("utf-8") if isinstance(body, bytes) else (body or "")+ try:+ payload = json.loads(body_text) if body_text else {}+ except json.JSONDecodeError:+ return error_response_json("SerializationException", "invalid JSON body", 400)+ return fn(payload)diff --git a/ministack/services/ec2.py b/ministack/services/ec2.pyindex c5d153a3..78ad0e95 100644--- a/ministack/services/ec2.py+++ b/ministack/services/ec2.py@@ -1486,6 +1486,64 @@ def _describe_availability_zones(p):f"<availabilityZoneInfo>{items}</availabilityZoneInfo>")+# Standard commercial AWS regions (us-gov-* / cn-* served by separate partitions+# in real AWS, so excluded). opt-in-not-required matches AWS for legacy regions+# enabled by default; newer regions surface as opted-in for the stub.+_AWS_REGIONS = [+ ("us-east-1", "opt-in-not-required"),+ ("us-east-2", "opt-in-not-required"),+ ("us-west-1", "opt-in-not-required"),+ ("us-west-2", "opt-in-not-required"),+ ("af-south-1", "opted-in"),+ ("ap-east-1", "opted-in"),+ ("ap-south-1", "opt-in-not-required"),+ ("ap-south-2", "opted-in"),+ ("ap-northeast-1", "opt-in-not-required"),+ ("ap-northeast-2", "opt-in-not-required"),+ ("ap-northeast-3", "opt-in-not-required"),+ ("ap-southeast-1", "opt-in-not-required"),+ ("ap-southeast-2", "opt-in-not-required"),+ ("ap-southeast-3", "opted-in"),+ ("ap-southeast-4", "opted-in"),+ ("ap-southeast-5", "opted-in"),+ ("ca-central-1", "opt-in-not-required"),+ ("ca-west-1", "opted-in"),+ ("eu-central-1", "opt-in-not-required"),+ ("eu-central-2", "opted-in"),+ ("eu-west-1", "opt-in-not-required"),+ ("eu-west-2", "opt-in-not-required"),+ ("eu-west-3", "opt-in-not-required"),+ ("eu-north-1", "opt-in-not-required"),+ ("eu-south-1", "opted-in"),+ ("eu-south-2", "opted-in"),+ ("il-central-1", "opted-in"),+ ("me-south-1", "opted-in"),+ ("me-central-1", "opted-in"),+ ("sa-east-1", "opt-in-not-required"),+ ("mx-central-1", "opted-in"),+]+++def _describe_regions(p):+ requested = _parse_member_list(p, "RegionName")+ all_regions = _p(p, "AllRegions", "").lower() == "true"+ items_xml = []+ for name, opt_in in _AWS_REGIONS:+ if requested and name not in requested:+ continue+ # Without AllRegions, AWS omits regions that are disabled (not-opted-in).+ # The stub treats every listed region as enabled, so AllRegions has no+ # filtering effect here — it's accepted for SDK compatibility.+ items_xml.append(+ f"<item><regionName>{name}</regionName>"+ f"<regionEndpoint>ec2.{name}.amazonaws.com</regionEndpoint>"+ f"<optInStatus>{opt_in}</optInStatus></item>"+ )+ _ = all_regions+ return _xml(200, "DescribeRegionsResponse",+ f"<regionInfo>{''.join(items_xml)}</regionInfo>")++# ---------------------------------------------------------------------------# Elastic IPs# ---------------------------------------------------------------------------@@ -4145,6 +4203,7 @@ _ACTION_MAP = {"AttachInternetGateway": _attach_internet_gateway,"DetachInternetGateway": _detach_internet_gateway,"DescribeAvailabilityZones": _describe_availability_zones,+ "DescribeRegions": _describe_regions,"AllocateAddress": _allocate_address,"ReleaseAddress": _release_address,"AssociateAddress": _associate_address,diff --git a/ministack/services/eventbridge.py b/ministack/services/eventbridge.pyindex c0fe423f..06b2fe1f 100644--- a/ministack/services/eventbridge.py+++ b/ministack/services/eventbridge.py@@ -270,17 +270,26 @@ def _create_event_bus(data):return error_response_json("ResourceAlreadyExistsException", f"Event bus {name} already exists", 400)arn = f"arn:aws:events:{get_region()}:{get_account_id()}:event-bus/{name}"description = data.get("Description", "")- _event_buses[name] = {+ bus_record = {"Name": name,"Arn": arn,"Description": description,"CreationTime": _now_ts(),"LastModifiedTime": _now_ts(),}+ # Optional 2026-03 additive fields — accept-and-echo so SDK callers+ # configuring rule-match logging round-trip cleanly.+ for k in ("LogConfig", "DeadLetterConfig", "KmsKeyIdentifier"):+ if k in data:+ bus_record[k] = data[k]+ _event_buses[name] = bus_recordtags = data.get("Tags", [])if tags:_tags[arn] = {t["Key"]: t["Value"] for t in tags}- return json_response({"EventBusArn": arn})+ out = {"EventBusArn": arn}+ if "LogConfig" in bus_record:+ out["LogConfig"] = bus_record["LogConfig"]+ return json_response(out)def _delete_event_bus(data):@@ -320,14 +329,18 @@ def _describe_event_bus(data):if not bus:return error_response_json("ResourceNotFoundException", f"Event bus {name} not found", 400)policy = _event_bus_policies.get(name)- return json_response({+ out = {"Name": bus["Name"],"Arn": bus["Arn"],"Description": bus.get("Description", ""),"CreationTime": bus["CreationTime"],"LastModifiedTime": bus.get("LastModifiedTime", bus.get("CreationTime")),"Policy": json.dumps(policy) if policy else "",- })+ }+ for k in ("LogConfig", "DeadLetterConfig", "KmsKeyIdentifier"):+ if k in bus:+ out[k] = bus[k]+ return json_response(out)def _update_event_bus(data):@@ -346,6 +359,9 @@ def _update_event_bus(data):bus["EventSourceName"] = data.get("EventSourceName")if "Description" in data:bus["Description"] = data.get("Description")+ for k in ("LogConfig", "DeadLetterConfig", "KmsKeyIdentifier"):+ if k in data:+ bus[k] = data[k]# Update tags if providedtags = data.get("Tags")@@ -1711,6 +1727,9 @@ def _parse_rate_seconds(expr: str) -> int | None:return n * 86400+_cron_skip_warned: set = set()++def _tick_scheduled_rules():"""Fire any enabled scheduled rule whose interval has elapsed."""now = _now_ts()@@ -1719,16 +1738,34 @@ def _tick_scheduled_rules():for (account_id, rule_key), rule in list(_rules._data.items()):if rule.get("State") != "ENABLED":continue- interval = _parse_rate_seconds(rule.get("ScheduleExpression", ""))+ expr = rule.get("ScheduleExpression", "")+ interval = _parse_rate_seconds(expr)if interval is None:- continue # cron() expressions not yet supported by the scheduler+ # cron() and unsupported expressions are stored but not fired.+ # Surface it once per (account, rule) so users can debug a rule+ # they expected to see invoke. Real AWS fires cron() schedules;+ # this is a tracked parity gap.+ if expr.startswith("cron(") and (account_id, rule_key) not in _cron_skip_warned:+ logger.info(+ "EventBridge: cron() schedule on rule '%s' (account %s) is "+ "stored but not auto-fired — ministack only auto-fires rate() "+ "rules at present.",+ rule.get("Name", rule_key), account_id,+ )+ _cron_skip_warned.add((account_id, rule_key))+ continuestate_key = (account_id, rule_key)if state_key not in _rule_last_fired:- # First time the scheduler sees this rule: start the countdown but- # don't fire yet. AWS fires rate() rules ~interval seconds after- # creation, not immediately.- _rule_last_fired[state_key] = now- continue+ # AWS doc: "the countdown begins when you create the rule" — anchor+ # to the rule's CreationTime so the first fire lands one full+ # interval after PutRule, not one full interval after the first+ # scheduler tick (which can lag up to _SCHEDULER_TICK_INTERVAL).+ _rule_last_fired[state_key] = rule.get("CreationTime", now)+ # Fall through so a rule whose CreationTime is already > interval+ # ago (e.g. restored from persistence) fires on this same tick+ # rather than waiting another full interval.+ if now - _rule_last_fired[state_key] < interval:+ continueif now - _rule_last_fired[state_key] < interval:continue_rule_last_fired[state_key] = now@@ -1788,5 +1825,6 @@ def reset():_partner_event_sources.clear()_event_buses.clear()_rule_last_fired.clear()+ _cron_skip_warned.clear()# The "default" bus is lazily recreated per-account on next access via# _ensure_default_bus(), so nothing to re-seed here.diff --git a/ministack/services/lambda_svc.py b/ministack/services/lambda_svc.pyindex f7c86d5c..b7b90bc0 100644--- a/ministack/services/lambda_svc.py+++ b/ministack/services/lambda_svc.py@@ -534,6 +534,12 @@ def _build_config(name: str, data: dict, code_zip: bytes | None = None) -> dict:config["TenancyConfig"] = data["TenancyConfig"]if "CapacityProviderConfig" in data:config["CapacityProviderConfig"] = data["CapacityProviderConfig"]+ # FileSystemConfigs is opaque at the wire level — historically EFS access+ # points (fsap-*), and as of 2026-04 also S3 bucket ARNs for the S3 mount+ # feature. The emulator doesn't actually mount; it just round-trips the+ # config so SDK/CFN/Terraform reads see what was set.+ if "FileSystemConfigs" in data:+ config["FileSystemConfigs"] = data["FileSystemConfigs"]return configdiff --git a/ministack/services/opensearch.py b/ministack/services/opensearch.pynew file mode 100644index 00000000..b48b5bee--- /dev/null+++ b/ministack/services/opensearch.py@@ -0,0 +1,677 @@+"""+Amazon OpenSearch Service emulator.++Management plane: rest-json on /2021-01-01/* (botocore service-2.json).+Data plane: in-memory by default (stub endpoint), optional real+``opensearchproject/opensearch`` container per domain when+``OPENSEARCH_DATAPLANE=1`` (same pattern as ElastiCache and RDS).+Optional ``opensearchproject/opensearch-dashboards`` sidecar per domain when+``OPENSEARCH_DASHBOARDS=1``.++Operations:+- CreateDomain, DescribeDomain, DescribeDomains, DeleteDomain, ListDomainNames+- UpdateDomainConfig, DescribeDomainConfig, DescribeDomainChangeProgress+- ListVersions, GetCompatibleVersions+- AddTags, ListTags, RemoveTags++State is account-scoped via AccountScopedDict so per-tenant isolation matches+the rest of ministack.+"""++import copy+import json+import logging+import os+import re+import threading+import time++from ministack.core.responses import (+ AccountScopedDict,+ apply_image_prefix,+ get_account_id,+ get_region,+ new_uuid,+)++logger = logging.getLogger("opensearch")++# ---------------------------------------------------------------------------+# Configuration+# ---------------------------------------------------------------------------++DOCKER_NETWORK = os.environ.get("DOCKER_NETWORK", "")+DATAPLANE_ENABLED = os.environ.get("OPENSEARCH_DATAPLANE", "0") == "1"+DASHBOARDS_ENABLED = os.environ.get("OPENSEARCH_DASHBOARDS", "0") == "1"+BASE_PORT = int(os.environ.get("OPENSEARCH_BASE_PORT", "14571"))+DASHBOARDS_BASE_PORT = int(os.environ.get("OPENSEARCH_DASHBOARDS_BASE_PORT", "15601"))+DEFAULT_IMAGE = os.environ.get("OPENSEARCH_IMAGE", "opensearchproject/opensearch:2.15.0")+DASHBOARDS_IMAGE = os.environ.get(+ "OPENSEARCH_DASHBOARDS_IMAGE", "opensearchproject/opensearch-dashboards:2.15.0"+)+ENDPOINT_OVERRIDE = os.environ.get("MINISTACK_OPENSEARCH_ENDPOINT", "")++# Versions returned by ListVersions / used by GetCompatibleVersions. Mirrors the+# subset AWS still supports for new domains (managed-service availability page,+# 2026-Q1).+_SUPPORTED_VERSIONS = [+ "OpenSearch_2.15", "OpenSearch_2.13", "OpenSearch_2.11", "OpenSearch_2.9",+ "OpenSearch_2.7", "OpenSearch_2.5", "OpenSearch_2.3", "OpenSearch_1.3",+ "OpenSearch_1.2", "OpenSearch_1.1", "OpenSearch_1.0",+ "Elasticsearch_7.10", "Elasticsearch_7.9", "Elasticsearch_7.8",+ "Elasticsearch_7.7", "Elasticsearch_7.4", "Elasticsearch_7.1",+ "Elasticsearch_6.8", "Elasticsearch_6.7", "Elasticsearch_6.5",+ "Elasticsearch_6.4", "Elasticsearch_6.3", "Elasticsearch_6.2",+ "Elasticsearch_6.0", "Elasticsearch_5.6", "Elasticsearch_5.5",+ "Elasticsearch_5.3", "Elasticsearch_5.1",+]++_DEFAULT_VERSION = "OpenSearch_2.15"++# AWS allows lowercase letters, digits, hyphens; first character must be+# lowercase letter; 3-28 chars.+_NAME_RE = re.compile(r"^[a-z][a-z0-9\-]{2,27}$")++# ---------------------------------------------------------------------------+# State (account-scoped)+# ---------------------------------------------------------------------------++_domains = AccountScopedDict() # name -> DomainStatus dict (+ private _* fields)+_tags = AccountScopedDict() # arn -> [{Key, Value}, ...]+_change_progress = AccountScopedDict() # name -> change progress record++# Port counter and Docker handle are process-global (data plane is shared).+_port_counter = [BASE_PORT]+_dashboards_port_counter = [DASHBOARDS_BASE_PORT]+_state_lock = threading.Lock()+_docker_client = None+++def reset():+ _domains.clear()+ _tags.clear()+ _change_progress.clear()+ docker = _get_docker()+ if docker is not None:+ for c in docker.containers.list(+ all=True,+ filters={"label": "com.ministack.service=opensearch"},+ ):+ try:+ c.stop(timeout=2)+ c.remove(force=True)+ except Exception:+ pass+++def get_state():+ return {+ "domains": copy.deepcopy(_domains),+ "tags": copy.deepcopy(_tags),+ "change_progress": copy.deepcopy(_change_progress),+ }+++def restore_state(data):+ if not data:+ return+ for store, key in (+ (_domains, "domains"),+ (_tags, "tags"),+ (_change_progress, "change_progress"),+ ):+ store.clear()+ for k, v in (data.get(key) or {}).items():+ store[k] = v+++# ---------------------------------------------------------------------------+# Wire helpers+# ---------------------------------------------------------------------------++def _json(status, body):+ return status, {"Content-Type": "application/json"}, json.dumps(body).encode()+++def _error(status, code, message):+ return _json(status, {"__type": code, "Message": message})+++def _arn(name):+ return f"arn:aws:es:{get_region()}:{get_account_id()}:domain/{name}"+++def _engine_type(version: str) -> str:+ return "Elasticsearch" if version.lower().startswith("elasticsearch") else "OpenSearch"+++def _public(d: dict) -> dict:+ """Strip internal _-prefixed bookkeeping fields before serialising."""+ return {k: v for k, v in d.items() if not k.startswith("_")}+++def _now() -> int:+ return int(time.time())+++# ---------------------------------------------------------------------------+# Docker container management+# ---------------------------------------------------------------------------++def _get_docker():+ global _docker_client+ if _docker_client is None:+ try:+ import docker+ _docker_client = docker.from_env()+ except Exception:+ pass+ return _docker_client+++def _container_name(domain_name: str) -> str:+ return f"ministack-opensearch-{domain_name}"+++def _dashboards_container_name(domain_name: str) -> str:+ return f"ministack-opensearch-dashboards-{domain_name}"+++def _spawn_dataplane(domain_name: str, engine_version: str):+ """Spawn an OpenSearch container.++ Returns ``(host, port, container_id, dashboards_endpoint, dashboards_cid)``.+ On any failure returns the stub endpoint shape so the management plane+ still works without a real cluster.+ """+ stub_host = f"{domain_name}.ministack.local"+ stub_port = 9200+ if ENDPOINT_OVERRIDE:+ host, _, port_s = ENDPOINT_OVERRIDE.partition(":")+ return host or stub_host, int(port_s or stub_port), None, None, None++ if not DATAPLANE_ENABLED:+ return stub_host, stub_port, None, None, None++ docker = _get_docker()+ if docker is None:+ logger.warning(+ "OpenSearch: OPENSEARCH_DATAPLANE=1 but Docker unavailable; "+ "falling back to stub endpoint"+ )+ return stub_host, stub_port, None, None, None++ with _state_lock:+ host_port = _port_counter[0]+ _port_counter[0] += 1+ dash_host_port = _dashboards_port_counter[0]+ _dashboards_port_counter[0] += 1++ image = apply_image_prefix(DEFAULT_IMAGE)+ labels = {+ "com.ministack.service": "opensearch",+ "com.ministack.domain": domain_name,+ "com.docker.compose.project": "ministack",+ }+ env_vars = {+ "discovery.type": "single-node",+ # Disable security plugin so test code can talk to the cluster+ # without bootstrapping a CA chain. Real AWS requires HTTPS+IAM;+ # matching that here would block every smoke test.+ "DISABLE_SECURITY_PLUGIN": "true",+ "OPENSEARCH_INITIAL_ADMIN_PASSWORD": "MinIstack-Admin-1!",+ }+ run_kwargs = dict(+ image=image, detach=True,+ ports={"9200/tcp": host_port},+ name=_container_name(domain_name),+ labels=labels,+ environment=env_vars,+ ulimits=[{"Name": "memlock", "Soft": -1, "Hard": -1}],+ )+ if DOCKER_NETWORK:+ run_kwargs["network"] = DOCKER_NETWORK++ cid = None+ endpoint_host, endpoint_port = "localhost", host_port+ try:+ container = docker.containers.run(**run_kwargs)+ cid = container.id+ if DOCKER_NETWORK:+ container.reload()+ networks = container.attrs.get("NetworkSettings", {}).get("Networks", {})+ ip = networks.get(DOCKER_NETWORK, {}).get("IPAddress", "")+ if ip:+ endpoint_host = ip+ endpoint_port = 9200+ logger.info(+ "OpenSearch: started container %s at %s:%s (image=%s)",+ domain_name, endpoint_host, endpoint_port, image,+ )+ except Exception as e:+ logger.warning("OpenSearch: Docker failed for %s: %s", domain_name, e)+ return stub_host, stub_port, None, None, None++ dash_endpoint, dash_cid = None, None+ if DASHBOARDS_ENABLED:+ try:+ dash_kwargs = dict(+ image=apply_image_prefix(DASHBOARDS_IMAGE),+ detach=True,+ ports={"5601/tcp": dash_host_port},+ name=_dashboards_container_name(domain_name),+ labels={**labels, "com.ministack.role": "dashboards"},+ environment={+ "OPENSEARCH_HOSTS": f"http://{_container_name(domain_name)}:9200",+ "DISABLE_SECURITY_DASHBOARDS_PLUGIN": "true",+ },+ )+ if DOCKER_NETWORK:+ dash_kwargs["network"] = DOCKER_NETWORK+ dash_container = docker.containers.run(**dash_kwargs)+ dash_cid = dash_container.id+ dash_endpoint = f"localhost:{dash_host_port}"+ logger.info(+ "OpenSearch Dashboards: started %s on port %s",+ domain_name, dash_host_port,+ )+ except Exception as e:+ logger.warning("OpenSearch Dashboards: failed for %s: %s", domain_name, e)++ return endpoint_host, endpoint_port, cid, dash_endpoint, dash_cid+++def _teardown_dataplane(rec: dict) -> None:+ docker = _get_docker()+ if docker is None:+ return+ for cid in (rec.get("_ContainerId"), rec.get("_DashboardsContainerId")):+ if not cid:+ continue+ try:+ c = docker.containers.get(cid)+ c.stop(timeout=2)+ c.remove(force=True)+ except Exception:+ pass+++# ---------------------------------------------------------------------------+# DomainStatus / DomainConfig builders+# ---------------------------------------------------------------------------++def _default_cluster_config(override=None):+ base = {+ "InstanceType": "m5.large.search",+ "InstanceCount": 1,+ "DedicatedMasterEnabled": False,+ "ZoneAwarenessEnabled": False,+ "WarmEnabled": False,+ "ColdStorageOptions": {"Enabled": False},+ }+ if override:+ base.update(override)+ return base+++def _default_ebs_options(override=None):+ base = {"EBSEnabled": True, "VolumeType": "gp3", "VolumeSize": 10}+ if override:+ base.update(override)+ return base+++def _new_domain_record(name, payload):+ engine_version = payload.get("EngineVersion", _DEFAULT_VERSION)+ cluster_cfg = _default_cluster_config(payload.get("ClusterConfig"))+ ebs_opts = _default_ebs_options(payload.get("EBSOptions"))+ access_policies = payload.get("AccessPolicies", "")++ host, port, cid, dash_endpoint, dash_cid = _spawn_dataplane(name, engine_version)+ endpoint = f"{host}:{port}"++ rec = {+ "DomainId": f"{get_account_id()}/{name}",+ "DomainName": name,+ "ARN": _arn(name),+ "Created": True,+ "Deleted": False,+ "Endpoint": endpoint,+ "Processing": False,+ "UpgradeProcessing": False,+ "EngineVersion": engine_version,+ "ClusterConfig": cluster_cfg,+ "EBSOptions": ebs_opts,+ "AccessPolicies": access_policies,+ "SnapshotOptions": {"AutomatedSnapshotStartHour": 0},+ "VPCOptions": payload.get("VPCOptions", {}),+ "CognitoOptions": payload.get("CognitoOptions", {"Enabled": False}),+ "EncryptionAtRestOptions": payload.get(+ "EncryptionAtRestOptions", {"Enabled": False}+ ),+ "NodeToNodeEncryptionOptions": payload.get(+ "NodeToNodeEncryptionOptions", {"Enabled": False}+ ),+ "AdvancedOptions": payload.get("AdvancedOptions", {}),+ "ServiceSoftwareOptions": {+ "CurrentVersion": engine_version,+ "NewVersion": "",+ "UpdateAvailable": False,+ "Cancellable": False,+ "UpdateStatus": "COMPLETED",+ "Description": "",+ "AutomatedUpdateDate": 0,+ "OptionalDeployment": True,+ },+ "DomainEndpointOptions": payload.get(+ "DomainEndpointOptions",+ {"EnforceHTTPS": True, "TLSSecurityPolicy": "Policy-Min-TLS-1-2-2019-07"},+ ),+ "AdvancedSecurityOptions": payload.get(+ "AdvancedSecurityOptions",+ {"Enabled": False, "InternalUserDatabaseEnabled": False},+ ),+ "AutoTuneOptions": {"State": "DISABLED"},+ "ChangeProgressDetails": {},+ "OffPeakWindowOptions": {"Enabled": False},+ "SoftwareUpdateOptions": {"AutoSoftwareUpdateEnabled": False},+ "_CreatedTime": _now(),+ "_UpdatedTime": _now(),+ "_ContainerId": cid,+ "_DashboardsContainerId": dash_cid,+ }+ if dash_endpoint:+ rec["DashboardEndpoint"] = dash_endpoint+ return rec+++def _option_status(create_ts, update_ts, version=1, state="Active"):+ return {+ "CreationDate": create_ts,+ "UpdateDate": update_ts,+ "UpdateVersion": version,+ "State": state,+ "PendingDeletion": False,+ }+++def _domain_config(rec: dict) -> dict:+ """Wrap each top-level option in {Options, Status} per AWS DomainConfig shape."""+ create = rec.get("_CreatedTime", _now())+ update = rec.get("_UpdatedTime", create)+ status = _option_status(create, update)++ def wrap(value):+ return {"Options": value, "Status": dict(status)}++ return {+ "EngineVersion": wrap(rec["EngineVersion"]),+ "ClusterConfig": wrap(rec["ClusterConfig"]),+ "EBSOptions": wrap(rec["EBSOptions"]),+ "AccessPolicies": wrap(rec["AccessPolicies"]),+ "SnapshotOptions": wrap(rec["SnapshotOptions"]),+ "VPCOptions": wrap(rec["VPCOptions"]),+ "CognitoOptions": wrap(rec["CognitoOptions"]),+ "EncryptionAtRestOptions": wrap(rec["EncryptionAtRestOptions"]),+ "NodeToNodeEncryptionOptions": wrap(rec["NodeToNodeEncryptionOptions"]),+ "AdvancedOptions": wrap(rec["AdvancedOptions"]),+ "DomainEndpointOptions": wrap(rec["DomainEndpointOptions"]),+ "AdvancedSecurityOptions": wrap(rec["AdvancedSecurityOptions"]),+ "AutoTuneOptions": wrap(rec["AutoTuneOptions"]),+ "ChangeProgressDetails": rec.get("ChangeProgressDetails", {}),+ "OffPeakWindowOptions": wrap(rec["OffPeakWindowOptions"]),+ "SoftwareUpdateOptions": wrap(rec["SoftwareUpdateOptions"]),+ }+++# ---------------------------------------------------------------------------+# Path matching+# ---------------------------------------------------------------------------++_DOMAIN_RE = re.compile(r"^/2021-01-01/(?:opensearch/)?domain(?:/(?P<name>[^/]+))?/?$")+_DOMAIN_INFO_RE = re.compile(r"^/2021-01-01/(?:opensearch/)?domain-info/?$")+_DOMAIN_CONFIG_RE = re.compile(r"^/2021-01-01/(?:opensearch/)?domain/(?P<name>[^/]+)/config/?$")+_DOMAIN_PROGRESS_RE = re.compile(r"^/2021-01-01/(?:opensearch/)?domain/(?P<name>[^/]+)/progress/?$")+_VERSIONS_RE = re.compile(r"^/2021-01-01/(?:opensearch/)?versions/?$")+_COMPAT_RE = re.compile(r"^/2021-01-01/(?:opensearch/)?compatibleVersions/?$")+_TAGS_RE = re.compile(r"^/2021-01-01/tags/?$")+_TAGS_REMOVAL_RE = re.compile(r"^/2021-01-01/tags-removal/?$")+++def _qp(query_params, key) -> str:+ if not query_params:+ return ""+ v = query_params.get(key)+ if isinstance(v, list):+ return v[0] if v else ""+ return v or ""+++# ---------------------------------------------------------------------------+# Operation handlers+# ---------------------------------------------------------------------------++def _create_domain(payload):+ name = payload.get("DomainName")+ if not name:+ return _error(400, "ValidationException", "DomainName is required")+ if not _NAME_RE.match(name):+ return _error(400, "ValidationException",+ "DomainName must start with a lowercase letter, contain only "+ "lowercase letters, digits, and hyphens, and be 3-28 characters")+ if name in _domains:+ return _error(409, "ResourceAlreadyExistsException",+ f"Domain already exists: {name}")+ rec = _new_domain_record(name, payload)+ _domains[name] = rec+ tag_list = payload.get("TagList") or []+ if tag_list:+ _tags[_arn(name)] = list(tag_list)+ return _json(200, {"DomainStatus": _public(rec)})+++def _describe_domain(name):+ rec = _domains.get(name)+ if not rec:+ return _error(404, "ResourceNotFoundException", f"Domain not found: {name}")+ return _json(200, {"DomainStatus": _public(rec)})+++def _delete_domain(name):+ rec = _domains.pop(name, None)+ if not rec:+ return _error(404, "ResourceNotFoundException", f"Domain not found: {name}")+ _teardown_dataplane(rec)+ _tags.pop(_arn(name), None)+ _change_progress.pop(name, None)+ out = dict(rec)+ out["Deleted"] = True+ return _json(200, {"DomainStatus": _public(out)})+++def _list_domain_names(query_params):+ engine_filter = _qp(query_params, "engineType")+ out = []+ for name, rec in _domains.items():+ etype = _engine_type(rec.get("EngineVersion", _DEFAULT_VERSION))+ if engine_filter and etype != engine_filter:+ continue+ out.append({"DomainName": name, "EngineType": etype})+ return _json(200, {"DomainNames": out})+++def _describe_domains(payload):+ names = payload.get("DomainNames") or []+ statuses = []+ for n in names:+ rec = _domains.get(n)+ if rec:+ statuses.append(_public(rec))+ return _json(200, {"DomainStatusList": statuses})+++def _update_domain_config(name, payload):+ rec = _domains.get(name)+ if not rec:+ return _error(404, "ResourceNotFoundException", f"Domain not found: {name}")+ updatable = {+ "ClusterConfig", "EBSOptions", "AccessPolicies", "SnapshotOptions",+ "VPCOptions", "CognitoOptions", "AdvancedOptions",+ "DomainEndpointOptions", "AdvancedSecurityOptions",+ "EncryptionAtRestOptions", "NodeToNodeEncryptionOptions",+ "AutoTuneOptions", "OffPeakWindowOptions", "SoftwareUpdateOptions",+ }+ for k, v in payload.items():+ if k in updatable:+ rec[k] = v+ rec["_UpdatedTime"] = _now()++ # Real AWS marks the domain Processing while config rollout happens; we+ # complete immediately because the data plane (if any) doesn't actually+ # re-provision.+ _change_progress[name] = {+ "ChangeId": new_uuid(),+ "StartTime": _now(),+ "Status": "COMPLETED",+ "PendingProperties": [],+ "CompletedProperties": list(payload.keys()),+ "TotalNumberOfStages": 0,+ "ConfigChangeStatus": "Completed",+ }+ return _json(200, {"DomainConfig": _domain_config(rec)})+++def _describe_domain_config(name):+ rec = _domains.get(name)+ if not rec:+ return _error(404, "ResourceNotFoundException", f"Domain not found: {name}")+ return _json(200, {"DomainConfig": _domain_config(rec)})+++def _describe_domain_change_progress(name, query_params):+ rec = _domains.get(name)+ if not rec:+ return _error(404, "ResourceNotFoundException", f"Domain not found: {name}")+ progress = _change_progress.get(name) or {+ "ChangeId": "",+ "StartTime": rec.get("_CreatedTime", _now()),+ "Status": "COMPLETED",+ "PendingProperties": [],+ "CompletedProperties": [],+ "TotalNumberOfStages": 0,+ "ConfigChangeStatus": "Completed",+ }+ return _json(200, {"ChangeProgressStatus": progress})+++def _list_versions(query_params):+ return _json(200, {"Versions": list(_SUPPORTED_VERSIONS)})+++def _get_compatible_versions(query_params):+ domain = _qp(query_params, "domainName")+ if domain:+ rec = _domains.get(domain)+ if not rec:+ return _error(404, "ResourceNotFoundException", f"Domain not found: {domain}")+ source = rec["EngineVersion"]+ targets = [v for v in _SUPPORTED_VERSIONS+ if _engine_type(v) == _engine_type(source) and v != source]+ return _json(200, {"CompatibleVersions": [+ {"SourceVersion": source, "TargetVersions": targets}+ ]})+ out = []+ for source in _SUPPORTED_VERSIONS:+ targets = [v for v in _SUPPORTED_VERSIONS+ if _engine_type(v) == _engine_type(source) and v != source]+ out.append({"SourceVersion": source, "TargetVersions": targets})+ return _json(200, {"CompatibleVersions": out})+++def _add_tags(payload):+ arn = payload.get("ARN")+ tag_list = payload.get("TagList") or []+ if not arn:+ return _error(400, "ValidationException", "ARN is required")+ existing = _tags.get(arn) or []+ by_key = {t["Key"]: t for t in existing}+ for t in tag_list:+ by_key[t["Key"]] = t+ _tags[arn] = list(by_key.values())+ return _json(200, {})+++def _list_tags(query_params):+ arn = _qp(query_params, "arn")+ if not arn:+ return _error(400, "ValidationException", "arn query parameter is required")+ return _json(200, {"TagList": list(_tags.get(arn) or [])})+++def _remove_tags(payload):+ arn = payload.get("ARN")+ keys = set(payload.get("TagKeys") or [])+ if not arn:+ return _error(400, "ValidationException", "ARN is required")+ existing = _tags.get(arn) or []+ _tags[arn] = [t for t in existing if t["Key"] not in keys]+ return _json(200, {})+++# ---------------------------------------------------------------------------+# Dispatcher+# ---------------------------------------------------------------------------++async def handle_request(method, path, headers, body_bytes, query_params):+ body_text = body_bytes.decode("utf-8") if body_bytes else ""+ try:+ payload = json.loads(body_text) if body_text else {}+ except json.JSONDecodeError:+ return _error(400, "InvalidPayloadException", "Request body is not valid JSON")++ p = path.rstrip("/")++ if method == "GET" and p == "/2021-01-01/domain":+ return _list_domain_names(query_params)++ if method == "GET" and _VERSIONS_RE.match(path):+ return _list_versions(query_params)++ if method == "GET" and _COMPAT_RE.match(path):+ return _get_compatible_versions(query_params)++ if _TAGS_REMOVAL_RE.match(path) and method == "POST":+ return _remove_tags(payload)+ if _TAGS_RE.match(path):+ if method == "POST":+ return _add_tags(payload)+ if method == "GET":+ return _list_tags(query_params)++ if method == "POST" and _DOMAIN_INFO_RE.match(path):+ return _describe_domains(payload)++ m = _DOMAIN_CONFIG_RE.match(path)+ if m:+ name = m.group("name")+ if method == "GET":+ return _describe_domain_config(name)+ if method == "POST":+ return _update_domain_config(name, payload)++ m = _DOMAIN_PROGRESS_RE.match(path)+ if method == "GET" and m:+ return _describe_domain_change_progress(m.group("name"), query_params)++ m = _DOMAIN_RE.match(path)+ if method == "POST" and m and m.group("name") is None:+ return _create_domain(payload)+ if m and m.group("name"):+ name = m.group("name")+ if method == "GET":+ return _describe_domain(name)+ if method == "DELETE":+ return _delete_domain(name)++ return _error(400, "InvalidAction",+ f"OpenSearch operation not implemented: {method} {path}")diff --git a/ministack/services/organizations.py b/ministack/services/organizations.pynew file mode 100644index 00000000..8a802fc3--- /dev/null+++ b/ministack/services/organizations.py@@ -0,0 +1,233 @@+"""+AWS Organizations stub.++JSON 1.1 protocol, target prefix ``AWSOrganizationsV20161128``.++Models a single-master-account organization. The master is whatever account+the request is made under (resolved via ``get_account_id``); the org returns+itself as ALL-features by default. Accounts and OUs are stored in+account-scoped state so each tenant gets its own org.++Includes the ``Path`` field on Account and OrganizationalUnit per the+2026-03-31 AWS additive change.+"""++import copy+import json+import logging+import time++from ministack.core.responses import (+ AccountScopedDict,+ error_response_json,+ get_account_id,+ new_uuid,+)++logger = logging.getLogger("organizations")+++# Per-master-account state. Each account that calls Organizations gets its+# own org graph; that mirrors how local-emulator multi-tenancy works.+_orgs = AccountScopedDict() # singleton "self" -> Organization dict+_accounts = AccountScopedDict() # account_id -> Account dict+_ous = AccountScopedDict() # ou_id -> OU dict (with ParentId)+_roots = AccountScopedDict() # root_id -> Root dict (single root)+++def reset():+ _orgs.clear()+ _accounts.clear()+ _ous.clear()+ _roots.clear()+++def get_state():+ return {+ "orgs": copy.deepcopy(_orgs),+ "accounts": copy.deepcopy(_accounts),+ "ous": copy.deepcopy(_ous),+ "roots": copy.deepcopy(_roots),+ }+++def restore_state(data):+ if not data:+ return+ for store, key in (+ (_orgs, "orgs"), (_accounts, "accounts"),+ (_ous, "ous"), (_roots, "roots")+ ):+ store.clear()+ for k, v in (data.get(key) or {}).items():+ store[k] = v+++def _json(status, body):+ return status, {"Content-Type": "application/x-amz-json-1.1"}, json.dumps(body).encode()+++def _ensure_org():+ """Lazily initialise the org for the current master account."""+ if "self" in _orgs:+ return+ master = get_account_id()+ org_id = "o-" + new_uuid().replace("-", "")[:10]+ root_id = "r-" + new_uuid().replace("-", "")[:6]+ _orgs["self"] = {+ "Id": org_id,+ "Arn": f"arn:aws:organizations::{master}:organization/{org_id}",+ "FeatureSet": "ALL",+ "MasterAccountArn": f"arn:aws:organizations::{master}:account/{org_id}/{master}",+ "MasterAccountId": master,+ "MasterAccountEmail": f"master+{master}@ministack.local",+ "AvailablePolicyTypes": [+ {"Type": "SERVICE_CONTROL_POLICY", "Status": "ENABLED"},+ ],+ }+ _roots[root_id] = {+ "Id": root_id,+ "Arn": f"arn:aws:organizations::{master}:root/{org_id}/{root_id}",+ "Name": "Root",+ "PolicyTypes": [],+ }+ # Master account record+ _accounts[master] = {+ "Id": master,+ "Arn": f"arn:aws:organizations::{master}:account/{org_id}/{master}",+ "Email": f"master+{master}@ministack.local",+ "Name": "Master Account",+ "Status": "ACTIVE",+ "JoinedMethod": "INVITED",+ "JoinedTimestamp": int(time.time()),+ "Path": "/",+ "_ParentId": root_id,+ }+++def _public_account(a: dict) -> dict:+ return {k: v for k, v in a.items() if not k.startswith("_")}+++def _public_ou(o: dict) -> dict:+ return {k: v for k, v in o.items() if not k.startswith("_")}+++def _describe_organization(_payload):+ _ensure_org()+ return _json(200, {"Organization": dict(_orgs["self"])})+++def _list_roots(_payload):+ _ensure_org()+ return _json(200, {"Roots": list(_roots.values()), "NextToken": None})+++def _list_accounts(_payload):+ _ensure_org()+ return _json(200, {+ "Accounts": [_public_account(a) for a in _accounts.values()],+ "NextToken": None,+ })+++def _describe_account(payload):+ _ensure_org()+ aid = payload.get("AccountId")+ if not aid:+ return error_response_json("InvalidInputException", "AccountId is required", 400)+ a = _accounts.get(aid)+ if not a:+ return error_response_json("AccountNotFoundException",+ f"Account {aid} not found", 400)+ return _json(200, {"Account": _public_account(a)})+++def _list_organizational_units_for_parent(payload):+ _ensure_org()+ parent_id = payload.get("ParentId") or ""+ out = [_public_ou(o) for o in _ous.values() if o.get("_ParentId") == parent_id]+ return _json(200, {"OrganizationalUnits": out, "NextToken": None})+++def _list_accounts_for_parent(payload):+ _ensure_org()+ parent_id = payload.get("ParentId") or ""+ out = [_public_account(a) for a in _accounts.values()+ if a.get("_ParentId") == parent_id]+ return _json(200, {"Accounts": out, "NextToken": None})+++def _create_organizational_unit(payload):+ _ensure_org()+ parent_id = payload.get("ParentId")+ name = payload.get("Name")+ if not parent_id or not name:+ return error_response_json("InvalidInputException",+ "ParentId and Name are required", 400)+ org_id = _orgs["self"]["Id"]+ master = get_account_id()+ ou_id = f"ou-{parent_id.split('-')[-1][:4]}-{new_uuid().replace('-','')[:10]}"+ parent_ou = _ous.get(parent_id)+ parent_path = (parent_ou or {}).get("Path", "/")+ rec = {+ "Id": ou_id,+ "Arn": f"arn:aws:organizations::{master}:ou/{org_id}/{ou_id}",+ "Name": name,+ "Path": (parent_path.rstrip("/") + "/" + name + "/") if parent_path != "/" else f"/{name}/",+ "_ParentId": parent_id,+ }+ _ous[ou_id] = rec+ return _json(200, {"OrganizationalUnit": _public_ou(rec)})+++def _describe_organizational_unit(payload):+ _ensure_org()+ ou_id = payload.get("OrganizationalUnitId")+ o = _ous.get(ou_id) if ou_id else None+ if not o:+ return error_response_json("OrganizationalUnitNotFoundException",+ f"OU {ou_id} not found", 400)+ return _json(200, {"OrganizationalUnit": _public_ou(o)})+++def _delete_organizational_unit(payload):+ _ensure_org()+ ou_id = payload.get("OrganizationalUnitId")+ if not ou_id or ou_id not in _ous:+ return error_response_json("OrganizationalUnitNotFoundException",+ f"OU {ou_id} not found", 400)+ del _ous[ou_id]+ return _json(200, {})+++_DISPATCH = {+ "DescribeOrganization": _describe_organization,+ "ListRoots": _list_roots,+ "ListAccounts": _list_accounts,+ "DescribeAccount": _describe_account,+ "ListOrganizationalUnitsForParent": _list_organizational_units_for_parent,+ "ListAccountsForParent": _list_accounts_for_parent,+ "CreateOrganizationalUnit": _create_organizational_unit,+ "DescribeOrganizationalUnit": _describe_organizational_unit,+ "DeleteOrganizationalUnit": _delete_organizational_unit,+}+++async def handle_request(method, path, headers, body, query_params):+ target = headers.get("X-Amz-Target") or headers.get("x-amz-target") or ""+ op = target.split(".", 1)[1] if "." in target else target+ if not op:+ return error_response_json("InvalidAction", "missing X-Amz-Target", 400)++ body_text = body.decode("utf-8") if isinstance(body, bytes) else (body or "")+ try:+ payload = json.loads(body_text) if body_text else {}+ except json.JSONDecodeError:+ return error_response_json("SerializationException", "invalid JSON body", 400)++ fn = _DISPATCH.get(op)+ if fn is None:+ return error_response_json("InvalidAction",+ f"Operation '{op}' not implemented", 400)+ return fn(payload)diff --git a/ministack/services/waf_v1.py b/ministack/services/waf_v1.pynew file mode 100644index 00000000..a49d2314--- /dev/null+++ b/ministack/services/waf_v1.py@@ -0,0 +1,110 @@+"""+WAF Classic + WAF Regional (v1) stub.++Minimal AWS-shape-correct responses for the v1 API. AWS deprecated v1 in favour+of WAFv2; most modern code paths use ``wafv2``. This module exists so SDK+clients targeting v1 (Terraform legacy, old CFN, JDK examples) get clean+empty-state responses instead of a 405.++Target prefixes:+- ``AWSWAF_20150824`` (waf — classic / global)+- ``AWSWAF_Regional_20161128`` (waf-regional)+"""++import json+import logging++from ministack.core.responses import (+ error_response_json,+ new_uuid,+)++logger = logging.getLogger("waf_v1")+++def _v1_response(data: dict, status: int = 200) -> tuple:+ """WAF v1 uses application/x-amz-json-1.1 (botocore metadata.jsonVersion)."""+ body = json.dumps(data, ensure_ascii=False).encode("utf-8")+ return status, {"Content-Type": "application/x-amz-json-1.1"}, body++# Map List* operation -> response member name. From botocore service-2.json+# (waf-regional 2016-11-28). Identical between waf and waf-regional.+_LIST_RESULT_KEYS = {+ "ListActivatedRulesInRuleGroup": "ActivatedRules",+ "ListByteMatchSets": "ByteMatchSets",+ "ListGeoMatchSets": "GeoMatchSets",+ "ListIPSets": "IPSets",+ "ListLoggingConfigurations": "LoggingConfigurations",+ "ListRateBasedRules": "Rules",+ "ListRegexMatchSets": "RegexMatchSets",+ "ListRegexPatternSets": "RegexPatternSets",+ "ListResourcesForWebACL": "ResourceArns",+ "ListRuleGroups": "RuleGroups",+ "ListRules": "Rules",+ "ListSizeConstraintSets": "SizeConstraintSets",+ "ListSqlInjectionMatchSets": "SqlInjectionMatchSets",+ "ListSubscribedRuleGroups": "RuleGroups",+ "ListTagsForResource": "TagInfoForResource",+ "ListWebACLs": "WebACLs",+ "ListXssMatchSets": "XssMatchSets",+}++_NOT_FOUND = "WAFNonexistentItemException"+++def _change_token():+ return new_uuid()+++async def handle_request(method, path, headers, body, query_params):+ target = headers.get("X-Amz-Target") or headers.get("x-amz-target") or ""+ op = target.split(".", 1)[1] if "." in target else target+ if not op:+ return error_response_json("InvalidAction", "missing X-Amz-Target", 400)++ try:+ body_text = body.decode("utf-8") if isinstance(body, bytes) else (body or "")+ except UnicodeDecodeError:+ body_text = ""+ try:+ _ = json.loads(body_text) if body_text else {}+ except json.JSONDecodeError:+ return error_response_json("SerializationException", "invalid JSON body", 400)++ if op in _LIST_RESULT_KEYS:+ key = _LIST_RESULT_KEYS[op]+ # ListTagsForResource returns a struct, not a list+ if op == "ListTagsForResource":+ return _v1_response({+ "NextMarker": None,+ "TagInfoForResource": {"ResourceARN": "", "TagList": []},+ })+ return _v1_response({key: [], "NextMarker": None})++ if op == "GetChangeToken":+ return _v1_response({"ChangeToken": _change_token()})++ if op == "GetChangeTokenStatus":+ # INSYNC is the terminal success status per the spec.+ return _v1_response({"ChangeTokenStatus": "INSYNC"})++ if op == "GetPermissionPolicy":+ return _v1_response({"Policy": ""})++ if op.startswith("Get"):+ return error_response_json(_NOT_FOUND,+ "The referenced item does not exist.", 400)++ if op.startswith("Create"):+ # Real AWS returns a typed structure with the created resource ++ # ChangeToken. The exact field name varies; the safest stub is to+ # return a generic shape — most clients only check the response code.+ return _v1_response({"ChangeToken": _change_token()})++ if op.startswith(("Update", "Delete", "Associate", "Disassociate",+ "Put", "TagResource", "UntagResource")):+ return _v1_response({"ChangeToken": _change_token()})++ return error_response_json("WAFInvalidOperationException",+ f"Operation '{op}' is not implemented in this stub.",+ 400)diff --git a/pyproject.toml b/pyproject.tomlindex 3a9403dc..364c21cb 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"[project]name = "ministack"-version = "1.3.22"+version = "1.3.23"description = "Free, open-source local AWS emulator — drop-in LocalStack replacement"readme = "README.md"license = { file = "LICENSE" }diff --git a/tests/test_account.py b/tests/test_account.pynew file mode 100644index 00000000..b49f2713--- /dev/null+++ b/tests/test_account.py@@ -0,0 +1,65 @@+import json+import urllib.request++import pytest++import boto3++[email protected](scope="module")+def acct():+ return boto3.client("account", endpoint_url="http://localhost:4566",+ region_name="us-east-1",+ aws_access_key_id="test", aws_secret_access_key="test")+++def test_account_get_account_information(acct):+ info = acct.get_account_information()+ assert info["AccountId"] == "000000000000"+ assert info["AccountName"]+ assert isinstance(info["AccountCreatedDate"], int) or hasattr(info["AccountCreatedDate"], "year")+++def test_account_get_account_information_includes_account_state_field():+ """AccountState added 2026-04-29; verify present on the wire even though+ older botocore may strip it."""+ req = urllib.request.Request(+ "http://localhost:4566/getAccountInformation",+ data=b"{}",+ headers={+ "Content-Type": "application/json",+ "Authorization": ("AWS4-HMAC-SHA256 Credential=test/20260101/"+ "us-east-1/account/aws4_request, SignedHeaders=, Signature=x"),+ },+ method="POST",+ )+ body = json.loads(urllib.request.urlopen(req).read())+ assert body["AccountState"] == "ACTIVE"+++def test_account_list_regions(acct):+ regions = acct.list_regions()["Regions"]+ names = {r["RegionName"]: r["RegionOptStatus"] for r in regions}+ assert "us-east-1" in names+ assert names["us-east-1"] == "ENABLED_BY_DEFAULT"+ # New regions should report opt-in required+ assert names.get("ap-southeast-5") in ("ENABLED", "ENABLED_BY_DEFAULT")+++def test_account_get_region_opt_status(acct):+ r = acct.get_region_opt_status(RegionName="eu-west-1")+ assert r["RegionName"] == "eu-west-1"+ assert r["RegionOptStatus"] in ("ENABLED_BY_DEFAULT", "ENABLED")+++def test_account_get_region_opt_status_unknown_region(acct):+ from botocore.exceptions import ClientError+ with pytest.raises(ClientError) as exc:+ acct.get_region_opt_status(RegionName="xx-nowhere-1")+ assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"+++def test_account_get_contact_information(acct):+ info = acct.get_contact_information()["ContactInformation"]+ assert info["FullName"]+ assert info["CountryCode"] == "US"diff --git a/tests/test_apigatewayv1.py b/tests/test_apigatewayv1.pyindex 0a3babde..c190c7f1 100644--- a/tests/test_apigatewayv1.py+++ b/tests/test_apigatewayv1.py@@ -1585,3 +1585,29 @@ def test_put_integration_response_persists_content_handling(apigw_v1, method_setstatusCode="200",)assert got.get("contentHandling") == ch_value+++def test_apigateway_v1_create_domain_name_accepts_new_tls_policy(apigw_v1):+ """securityPolicy must accept the 2026-03 added enum value+ SecurityPolicy-TLS13-1-2-FIPS-PFS-PQ-2025-09 and any future opaque values."""+ domain = f"api-tls-{_uuid_mod.uuid4().hex[:8]}.example.com"+ new_policy = "SecurityPolicy-TLS13-1-2-FIPS-PFS-PQ-2025-09"+ r = apigw_v1.create_domain_name(+ domainName=domain,+ certificateName="c1",+ certificateArn=f"arn:aws:acm:us-east-1:000000000000:certificate/{_uuid_mod.uuid4().hex[:8]}",+ securityPolicy=new_policy,+ )+ assert r["securityPolicy"] == new_policy+ got = apigw_v1.get_domain_name(domainName=domain)+ assert got["securityPolicy"] == new_policy+++def test_apigateway_v1_create_domain_name_default_tls_policy(apigw_v1):+ """When securityPolicy is omitted, AWS defaults to TLS_1_2."""+ domain = f"api-tls-default-{_uuid_mod.uuid4().hex[:8]}.example.com"+ r = apigw_v1.create_domain_name(+ domainName=domain,+ certificateName="c2",+ )+ assert r["securityPolicy"] == "TLS_1_2"diff --git a/tests/test_batch.py b/tests/test_batch.pynew file mode 100644index 00000000..efe8392d--- /dev/null+++ b/tests/test_batch.py@@ -0,0 +1,100 @@+import boto3+import pytest++ENDPOINT = "http://localhost:4566"+REGION = "us-east-1"+++def _client(service, account="test"):+ return boto3.client(service, endpoint_url=ENDPOINT, region_name=REGION,+ aws_access_key_id=account, aws_secret_access_key="test")++[email protected](scope="module")+def batch():+ return _client("batch")+++def _client_for(account):+ return _client("batch", account=account)+++def _uid():+ import uuid+ return uuid.uuid4().hex[:8]+++def test_batch_describe_empty_lists(batch):+ assert isinstance(batch.describe_compute_environments()["computeEnvironments"], list)+ assert isinstance(batch.describe_job_queues()["jobQueues"], list)+++def test_batch_full_lifecycle(batch):+ """ComputeEnv -> JobQueue -> JobDefinition -> SubmitJob (auto-SUCCEEDED) -> ListJobs."""+ ce_name = f"ce-{_uid()}"+ jq_name = f"jq-{_uid()}"+ jd_name = f"jd-{_uid()}"+ job_name = f"j-{_uid()}"++ ce = batch.create_compute_environment(+ computeEnvironmentName=ce_name,+ type="MANAGED",+ serviceRole="arn:aws:iam::000000000000:role/batch",+ )+ assert ce["computeEnvironmentArn"].endswith(f"compute-environment/{ce_name}")++ jq = batch.create_job_queue(+ jobQueueName=jq_name,+ priority=1,+ computeEnvironmentOrder=[{"order": 1, "computeEnvironment": ce["computeEnvironmentArn"]}],+ )+ assert jq["jobQueueArn"].endswith(f"job-queue/{jq_name}")++ jd = batch.register_job_definition(+ jobDefinitionName=jd_name,+ type="container",+ containerProperties={"image": "busybox", "memory": 128, "vcpus": 1},+ )+ assert jd["revision"] == 1++ sj = batch.submit_job(jobName=job_name, jobQueue=jq["jobQueueArn"], jobDefinition=jd["jobDefinitionArn"])+ job_id = sj["jobId"]++ described = batch.describe_jobs(jobs=[job_id])["jobs"]+ assert len(described) == 1+ assert described[0]["status"] == "SUCCEEDED"+ assert described[0]["container"]["exitCode"] == 0++ listed = batch.list_jobs(jobQueue=jq_name)["jobSummaryList"]+ assert any(j["jobId"] == job_id for j in listed)+++def test_batch_register_job_definition_revisions(batch):+ name = f"rev-{_uid()}"+ r1 = batch.register_job_definition(jobDefinitionName=name, type="container",+ containerProperties={"image": "a", "memory": 128, "vcpus": 1})+ r2 = batch.register_job_definition(jobDefinitionName=name, type="container",+ containerProperties={"image": "b", "memory": 128, "vcpus": 1})+ assert r1["revision"] == 1+ assert r2["revision"] == 2+++def test_batch_describe_job_queue_by_name_or_arn(batch):+ name = f"lookup-{_uid()}"+ batch.create_job_queue(jobQueueName=name, priority=1, computeEnvironmentOrder=[])+ by_name = batch.describe_job_queues(jobQueues=[name])["jobQueues"]+ assert any(q["jobQueueName"] == name for q in by_name)+ arn = by_name[0]["jobQueueArn"]+ by_arn = batch.describe_job_queues(jobQueues=[arn])["jobQueues"]+ assert any(q["jobQueueName"] == name for q in by_arn)+++def test_batch_account_isolation():+ a = _client_for("555555555555")+ b = _client_for("666666666666")+ name = f"iso-{_uid()}"+ a.create_job_queue(jobQueueName=name, priority=1, computeEnvironmentOrder=[])+ a_qs = [q["jobQueueName"] for q in a.describe_job_queues()["jobQueues"]]+ b_qs = [q["jobQueueName"] for q in b.describe_job_queues()["jobQueues"]]+ assert name in a_qs+ assert name not in b_qsdiff --git a/tests/test_ec2.py b/tests/test_ec2.pyindex deb3ef68..3d6fa3a9 100644--- a/tests/test_ec2.py+++ b/tests/test_ec2.py@@ -24,6 +24,31 @@ def test_ec2_describe_availability_zones(ec2):azs = [az["ZoneName"] for az in resp["AvailabilityZones"]]assert any("us-east-1" in az for az in azs)++def test_ec2_describe_regions_returns_commercial_regions(ec2):+ """DescribeRegions must list at least the four legacy us-* regions+ with opt-in-not-required, and emit the shape AWS returns."""+ resp = ec2.describe_regions()+ regions = {r["RegionName"]: r for r in resp["Regions"]}+ for name in ("us-east-1", "us-east-2", "us-west-1", "us-west-2"):+ assert name in regions+ assert regions[name]["OptInStatus"] == "opt-in-not-required"+ assert regions[name]["Endpoint"] == f"ec2.{name}.amazonaws.com"+++def test_ec2_describe_regions_with_filter(ec2):+ resp = ec2.describe_regions(RegionNames=["us-east-1", "eu-west-1"])+ names = {r["RegionName"] for r in resp["Regions"]}+ assert names == {"us-east-1", "eu-west-1"}+++def test_ec2_describe_regions_all_regions_includes_opt_in(ec2):+ base = len(ec2.describe_regions()["Regions"])+ full = len(ec2.describe_regions(AllRegions=True)["Regions"])+ assert full == base+ assert base >= 30++def test_ec2_run_describe_terminate_instances(ec2):resp = ec2.run_instances(ImageId="ami-00000000", MinCount=1, MaxCount=1, InstanceType="t2.micro")assert len(resp["Instances"]) == 1diff --git a/tests/test_eventbridge.py b/tests/test_eventbridge.pyindex 2edf0111..5d4e104b 100644--- a/tests/test_eventbridge.py+++ b/tests/test_eventbridge.py@@ -1166,121 +1166,37 @@ def test_eventbridge_duplicate_replay_name_fails(eb):eb.delete_archive(ArchiveName=arch_name)-# ----------------------------------------------------------------------------# Scheduled rule auto-fire — H1 confirmation test-# -----------------------------------------------------------------------------# How long to wait for the scheduler to fire, in seconds.-# The background ticker runs every 10s. A rate(1 minute) rule fires ~60s after-# creation (AWS behavior: interval countdown starts at creation time).-# 80s = 60s interval + 10s max tick lag + 10s buffer.-# Override via EB_AUTOFIRE_WAIT for slower environments.-_EB_AUTOFIRE_WAIT = int(os.environ.get("EB_AUTOFIRE_WAIT", "80"))--# The endpoint ministack is reachable at from inside the Lambda execution context.-# For in-process Lambda execution (used by the test executor) this is the same as-# the test endpoint. Override via MINISTACK_LAMBDA_ENDPOINT if your Lambda executor-# runs in Docker and needs a different host (e.g. http://host.docker.internal:4566).-_MINISTACK_ENDPOINT = os.environ.get(- "MINISTACK_LAMBDA_ENDPOINT",- os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566"),-)--- os.environ.get("MINISTACK_SLOW_TESTS") != "1",- reason="Set MINISTACK_SLOW_TESTS=1 to run this slow scheduler integration test",-)-def test_eventbridge_scheduled_rule_autofire(eb, lam, sqs):- """Verify that a rate(1 minute) EventBridge rule auto-invokes its Lambda target.-- Per AWS docs, the interval countdown starts at rule creation time, so the- first invocation arrives ~60 seconds after creation. The background ticker- checks every 10 seconds, so with an 80-second default wait there is ample- headroom for one full cycle to complete.-- Run manually:- MINISTACK_SLOW_TESTS=1 pytest tests/test_eventbridge.py::test_eventbridge_scheduled_rule_autofire -v- """- uid = _uuid_mod.uuid4().hex[:8]- queue_name = f"eb-autofire-q-{uid}"- fn_name = f"eb-autofire-fn-{uid}"- rule_name = f"eb-autofire-rule-{uid}"-- # SQS queue acts as an invocation counter: each Lambda call sends one message.- q = sqs.create_queue(QueueName=queue_name)- queue_url = q["QueueUrl"]-- # Lambda writes a message to SQS on every invocation so we can count calls from- # outside the Lambda process.- handler_src = (- "import boto3, json, os\n"- "_sqs = boto3.client(\n"- " 'sqs', endpoint_url=os.environ['MINISTACK_ENDPOINT'],\n"- " aws_access_key_id='test', aws_secret_access_key='test',\n"- " region_name='us-east-1')\n"- "def handler(event, context):\n"- " _sqs.send_message(QueueUrl=os.environ['QUEUE_URL'], MessageBody='tick')\n"- " return {'ok': True}\n"- )- buf = io.BytesIO()- with zipfile.ZipFile(buf, "w") as zf:- zf.writestr("index.py", handler_src)- zip_bytes = buf.getvalue()-- lam.create_function(- FunctionName=fn_name,- Runtime="python3.12",- Role="arn:aws:iam::000000000000:role/test-role",- Handler="index.handler",- Code={"ZipFile": zip_bytes},- Environment={"Variables": {- "MINISTACK_ENDPOINT": _MINISTACK_ENDPOINT,- "QUEUE_URL": queue_url,- }},- Timeout=15,- )- fn_arn = lam.get_function(FunctionName=fn_name)["Configuration"]["FunctionArn"]-- # Wire the EventBridge rule: rate(1 minute), targeting the Lambda.- eb.put_rule(Name=rule_name, ScheduleExpression="rate(1 minute)", State="ENABLED")- rule_arn = eb.describe_rule(Name=rule_name)["Arn"]- eb.put_targets(Rule=rule_name, Targets=[{"Id": "autofire-target", "Arn": fn_arn}])- lam.add_permission(- FunctionName=fn_name,- StatementId="allow-events",- Action="lambda:InvokeFunction",- Principal="events.amazonaws.com",- SourceArn=rule_arn,- )-- # Wait long enough to catch at least one scheduler tick if one exists.- time.sleep(_EB_AUTOFIRE_WAIT)-- # Count invocations via SQS. Receive up to 10 messages; one per scheduler tick.- msgs = sqs.receive_message(- QueueUrl=queue_url,- MaxNumberOfMessages=10,- WaitTimeSeconds=0,- ).get("Messages", [])- invocation_count = len(msgs)-- # Cleanup — always runs even when xfail fires.- try:- eb.remove_targets(Rule=rule_name, Ids=["autofire-target"])- eb.delete_rule(Name=rule_name)- lam.delete_function(FunctionName=fn_name)- sqs.delete_queue(QueueUrl=queue_url)- except Exception:- pass+def test_eventbridge_log_config_round_trip(eb):+ """LogConfig accept-and-echo (2026-03 AWS additive change) — must+ persist on Create, echo on Describe, update via UpdateEventBus.+ Older botocore strict-validates this new field, so call via raw HTTP."""+ import urllib.request as _r+ name = f"log-bus-{int(time.time()*1000)}"+ log_cfg = {"IncludeDetail": "FULL", "Level": "INFO"}++ def _post(target, payload):+ req = _r.Request(+ "http://localhost:4566/",+ data=json.dumps(payload).encode(),+ headers={+ "X-Amz-Target": f"AWSEvents.{target}",+ "Content-Type": "application/x-amz-json-1.1",+ "Authorization": ("AWS4-HMAC-SHA256 Credential=test/20260101/"+ "us-east-1/events/aws4_request, SignedHeaders=, Signature=x"),+ },+ )+ return json.loads(_r.urlopen(req).read())- assert invocation_count > 0, (- f"Expected ≥1 scheduled invocation after {_EB_AUTOFIRE_WAIT}s "- f"but got {invocation_count}. "- "The EventBridge background scheduler did not fire the rate(1 minute) rule."- )+ _post("CreateEventBus", {"Name": name, "LogConfig": log_cfg})+ desc = _post("DescribeEventBus", {"Name": name})+ assert desc.get("LogConfig") == log_cfg+ new_cfg = {"IncludeDetail": "NONE", "Level": "ERROR"}+ _post("UpdateEventBus", {"Name": name, "LogConfig": new_cfg})+ desc2 = _post("DescribeEventBus", {"Name": name})+ assert desc2.get("LogConfig") == new_cfg+ eb.delete_event_bus(Name=name)# ---------------------------------------------------------------------------# Unit tests: _parse_rate_seconds# ---------------------------------------------------------------------------@@ -1413,3 +1329,38 @@ def test_scheduler_reset_clears_last_fired(isolated_scheduler):_eb._rule_last_fired[_STATE_KEY] = _eb._now_ts()_eb.reset()assert _eb._rule_last_fired == {}+++def test_scheduler_first_sight_with_old_creation_time_fires_immediately(isolated_scheduler):+ """AWS doc: 'the countdown begins when you create the rule'. A rule whose+ CreationTime is already older than the interval must fire on the first+ scheduler tick that observes it, not wait another full interval."""+ _eb._rules._data[_STATE_KEY] = {+ "Name": "old-rule",+ "ScheduleExpression": "rate(1 minute)",+ "State": "ENABLED",+ "EventBusName": "default",+ "Arn": "arn:aws:events:us-east-1:000000000000:rule/old-rule",+ "CreationTime": _eb._now_ts() - 120, # created 2 min ago, interval = 1 min+ }+ _eb._targets._data[_STATE_KEY] = list(_DUMMY_TARGET)+ with _patch("ministack.services.eventbridge._invoke_target") as mock_invoke:+ _eb._tick_scheduled_rules()+ mock_invoke.assert_called_once()+++def test_scheduler_first_sight_with_recent_creation_time_waits(isolated_scheduler):+ """A rule created within the last interval must NOT fire on first sight —+ AWS countdown begins at PutRule, so the first fire is one full interval later."""+ _eb._rules._data[_STATE_KEY] = {+ "Name": "fresh-rule",+ "ScheduleExpression": "rate(1 minute)",+ "State": "ENABLED",+ "EventBusName": "default",+ "Arn": "arn:aws:events:us-east-1:000000000000:rule/fresh-rule",+ "CreationTime": _eb._now_ts() - 5, # created 5s ago, interval = 60s+ }+ _eb._targets._data[_STATE_KEY] = list(_DUMMY_TARGET)+ with _patch("ministack.services.eventbridge._invoke_target") as mock_invoke:+ _eb._tick_scheduled_rules()+ mock_invoke.assert_not_called()diff --git a/tests/test_lambda.py b/tests/test_lambda.pyindex e6741b3a..60b1ad3d 100644--- a/tests/test_lambda.py+++ b/tests/test_lambda.py@@ -3040,3 +3040,26 @@ def test_lambda_docker_flags_applied_to_run_kwargs(monkeypatch):assert captured["privileged"] is Trueassert captured["read_only"] is Trueassert "unknown_flag" not in captured+++def test_lambda_filesystem_configs_s3_mount_round_trip(lam):+ """FileSystemConfigs accept-and-echo: AWS added S3-bucket ARN support+ in 2026-04 alongside the original EFS access-point ARNs. The emulator+ doesn't mount anything; it just round-trips the config so SDK/CFN reads+ see what was set."""+ fn = f"fs-mount-{int(time.time()*1000)}"+ lam.create_function(+ FunctionName=fn,+ Runtime="python3.12",+ Role=_LAMBDA_ROLE,+ Handler="index.handler",+ Code={"ZipFile": _make_zip(_LAMBDA_CODE)},+ FileSystemConfigs=[{+ "Arn": "arn:aws:s3:::my-bucket",+ "LocalMountPath": "/mnt/data",+ }],+ )+ cfg = lam.get_function_configuration(FunctionName=fn)+ assert cfg["FileSystemConfigs"] == [{"Arn": "arn:aws:s3:::my-bucket",+ "LocalMountPath": "/mnt/data"}]+ lam.delete_function(FunctionName=fn)diff --git a/tests/test_opensearch.py b/tests/test_opensearch.pynew file mode 100644index 00000000..5767e474--- /dev/null+++ b/tests/test_opensearch.py@@ -0,0 +1,304 @@+"""OpenSearch Service tests.++Covers the full management plane (13 ops) plus account isolation. The data+plane (real ``opensearchproject/opensearch`` container per domain) is gated+by ``OPENSEARCH_DATAPLANE=1`` and exercised separately when that env var+is set.+"""++import os+import time+import uuid++import boto3+import pytest+from botocore.exceptions import ClientError+++ENDPOINT = "http://localhost:4566"+REGION = "us-east-1"+++def _client(account="test"):+ return boto3.client(+ "opensearch",+ endpoint_url=ENDPOINT,+ region_name=REGION,+ aws_access_key_id=account,+ aws_secret_access_key="test",+ )++[email protected](scope="module")+def os_client():+ return _client()+++def _uid():+ return uuid.uuid4().hex[:6]+++# ---------------------------------------------------------------------------+# Lifecycle+# ---------------------------------------------------------------------------++def test_opensearch_create_describe_delete(os_client):+ name = f"d-{_uid()}"+ rec = os_client.create_domain(DomainName=name, EngineVersion="OpenSearch_2.13")["DomainStatus"]+ assert rec["DomainName"] == name+ assert rec["EngineVersion"] == "OpenSearch_2.13"+ assert rec["ARN"].startswith("arn:aws:es:")+ assert rec["DomainEndpointOptions"]["EnforceHTTPS"] is True++ desc = os_client.describe_domain(DomainName=name)["DomainStatus"]+ assert desc["DomainName"] == name++ deleted = os_client.delete_domain(DomainName=name)["DomainStatus"]+ assert deleted["Deleted"] is True+++def test_opensearch_describe_missing(os_client):+ with pytest.raises(ClientError) as exc:+ os_client.describe_domain(DomainName="nope-xyz")+ assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"+++def test_opensearch_create_duplicate(os_client):+ name = f"dup-{_uid()}"+ os_client.create_domain(DomainName=name)+ try:+ with pytest.raises(ClientError) as exc:+ os_client.create_domain(DomainName=name)+ assert exc.value.response["Error"]["Code"] == "ResourceAlreadyExistsException"+ finally:+ os_client.delete_domain(DomainName=name)+++def test_opensearch_invalid_name_rejected(os_client):+ """AWS DomainName rules: lowercase, 3-28 chars, alphanumeric + hyphens,+ first char must be a lowercase letter."""+ with pytest.raises(ClientError) as exc:+ os_client.create_domain(DomainName="UpperCase")+ assert exc.value.response["Error"]["Code"] == "ValidationException"+++def test_opensearch_describe_domains_filters_unknown(os_client):+ a = f"d-{_uid()}"+ os_client.create_domain(DomainName=a)+ try:+ out = os_client.describe_domains(DomainNames=[a, "ghost-domain-xyz"])+ names = [d["DomainName"] for d in out["DomainStatusList"]]+ assert a in names+ assert "ghost-domain-xyz" not in names+ finally:+ os_client.delete_domain(DomainName=a)+++# ---------------------------------------------------------------------------+# ListDomainNames+# ---------------------------------------------------------------------------++def test_opensearch_list_domain_names_engine_filter(os_client):+ es_name = f"es-{_uid()}"+ os_name = f"os-{_uid()}"+ os_client.create_domain(DomainName=es_name, EngineVersion="Elasticsearch_7.10")+ os_client.create_domain(DomainName=os_name, EngineVersion="OpenSearch_2.11")+ try:+ es_only = {d["DomainName"]: d["EngineType"]+ for d in os_client.list_domain_names(EngineType="Elasticsearch")["DomainNames"]}+ assert es_only.get(es_name) == "Elasticsearch"+ assert os_name not in es_only+ finally:+ os_client.delete_domain(DomainName=es_name)+ os_client.delete_domain(DomainName=os_name)+++# ---------------------------------------------------------------------------+# DomainConfig (Update/Describe/Progress)+# ---------------------------------------------------------------------------++def test_opensearch_describe_domain_config_wraps_options_status(os_client):+ name = f"cfg-{_uid()}"+ os_client.create_domain(DomainName=name)+ try:+ cfg = os_client.describe_domain_config(DomainName=name)["DomainConfig"]+ for key in ("EngineVersion", "ClusterConfig", "EBSOptions",+ "AccessPolicies", "DomainEndpointOptions"):+ assert key in cfg, f"missing {key}"+ entry = cfg[key]+ assert "Options" in entry, f"{key} missing Options"+ assert "Status" in entry, f"{key} missing Status"+ assert entry["Status"]["State"] == "Active"+ finally:+ os_client.delete_domain(DomainName=name)+++def test_opensearch_update_domain_config_persists(os_client):+ name = f"upd-{_uid()}"+ os_client.create_domain(DomainName=name)+ try:+ new_cluster = {+ "InstanceType": "r5.large.search",+ "InstanceCount": 3,+ "DedicatedMasterEnabled": True,+ "DedicatedMasterCount": 3,+ "DedicatedMasterType": "m5.large.search",+ "ZoneAwarenessEnabled": True,+ "ZoneAwarenessConfig": {"AvailabilityZoneCount": 3},+ "WarmEnabled": False,+ "ColdStorageOptions": {"Enabled": False},+ }+ out = os_client.update_domain_config(DomainName=name, ClusterConfig=new_cluster)+ assert out["DomainConfig"]["ClusterConfig"]["Options"]["InstanceCount"] == 3+ assert out["DomainConfig"]["ClusterConfig"]["Options"]["InstanceType"] == "r5.large.search"++ cfg = os_client.describe_domain_config(DomainName=name)["DomainConfig"]+ assert cfg["ClusterConfig"]["Options"]["InstanceCount"] == 3+ finally:+ os_client.delete_domain(DomainName=name)+++def test_opensearch_describe_domain_change_progress(os_client):+ name = f"prog-{_uid()}"+ os_client.create_domain(DomainName=name)+ try:+ p0 = os_client.describe_domain_change_progress(DomainName=name)["ChangeProgressStatus"]+ assert p0["Status"] == "COMPLETED"++ os_client.update_domain_config(DomainName=name, AccessPolicies="{}")+ p1 = os_client.describe_domain_change_progress(DomainName=name)["ChangeProgressStatus"]+ assert p1["Status"] == "COMPLETED"+ assert "AccessPolicies" in p1["CompletedProperties"]+ assert p1["ChangeId"]+ finally:+ os_client.delete_domain(DomainName=name)+++# ---------------------------------------------------------------------------+# Versions+# ---------------------------------------------------------------------------++def test_opensearch_list_versions_includes_recent(os_client):+ versions = os_client.list_versions()["Versions"]+ assert "OpenSearch_2.15" in versions+ assert "Elasticsearch_7.10" in versions+++def test_opensearch_get_compatible_versions_for_domain(os_client):+ name = f"compat-{_uid()}"+ os_client.create_domain(DomainName=name, EngineVersion="OpenSearch_2.11")+ try:+ compat = os_client.get_compatible_versions(DomainName=name)["CompatibleVersions"]+ assert len(compat) == 1+ assert compat[0]["SourceVersion"] == "OpenSearch_2.11"+ assert "OpenSearch_2.11" not in compat[0]["TargetVersions"]+ assert all(v.startswith("OpenSearch") for v in compat[0]["TargetVersions"])+ finally:+ os_client.delete_domain(DomainName=name)+++def test_opensearch_get_compatible_versions_no_domain_returns_matrix(os_client):+ out = os_client.get_compatible_versions()["CompatibleVersions"]+ sources = {entry["SourceVersion"] for entry in out}+ assert "OpenSearch_2.15" in sources+ assert "Elasticsearch_7.10" in sources+++# ---------------------------------------------------------------------------+# Tags+# ---------------------------------------------------------------------------++def test_opensearch_tag_lifecycle(os_client):+ name = f"tag-{_uid()}"+ rec = os_client.create_domain(DomainName=name)["DomainStatus"]+ arn = rec["ARN"]+ try:+ os_client.add_tags(ARN=arn, TagList=[+ {"Key": "Env", "Value": "Test"},+ {"Key": "Owner", "Value": "ministack"},+ ])+ tags = {t["Key"]: t["Value"] for t in os_client.list_tags(ARN=arn)["TagList"]}+ assert tags == {"Env": "Test", "Owner": "ministack"}++ os_client.add_tags(ARN=arn, TagList=[{"Key": "Env", "Value": "Prod"}])+ tags = {t["Key"]: t["Value"] for t in os_client.list_tags(ARN=arn)["TagList"]}+ assert tags["Env"] == "Prod"+ assert tags["Owner"] == "ministack"++ os_client.remove_tags(ARN=arn, TagKeys=["Env"])+ tags = {t["Key"]: t["Value"] for t in os_client.list_tags(ARN=arn)["TagList"]}+ assert "Env" not in tags+ assert tags["Owner"] == "ministack"+ finally:+ os_client.delete_domain(DomainName=name)+++def test_opensearch_create_with_tag_list(os_client):+ name = f"ctag-{_uid()}"+ rec = os_client.create_domain(+ DomainName=name,+ TagList=[{"Key": "ProjectId", "Value": "X"}],+ )["DomainStatus"]+ try:+ tags = {t["Key"]: t["Value"] for t in os_client.list_tags(ARN=rec["ARN"])["TagList"]}+ assert tags == {"ProjectId": "X"}+ finally:+ os_client.delete_domain(DomainName=name)+++# ---------------------------------------------------------------------------+# Multi-tenant+# ---------------------------------------------------------------------------++def test_opensearch_account_isolation():+ a = _client("111111111111")+ b = _client("222222222222")+ name = f"acct-{_uid()}"+ a.create_domain(DomainName=name)+ try:+ a_listed = [d["DomainName"] for d in a.list_domain_names()["DomainNames"]]+ b_listed = [d["DomainName"] for d in b.list_domain_names()["DomainNames"]]+ assert name in a_listed+ assert name not in b_listed+ with pytest.raises(ClientError) as exc:+ b.describe_domain(DomainName=name)+ assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"+ finally:+ a.delete_domain(DomainName=name)+++# ---------------------------------------------------------------------------+# Data plane (gated)+# ---------------------------------------------------------------------------++ os.environ.get("OPENSEARCH_DATAPLANE") != "1",+ reason="set OPENSEARCH_DATAPLANE=1 to run the real-cluster smoke",+)+def test_opensearch_dataplane_cluster_health():+ """When OPENSEARCH_DATAPLANE=1 is set on the ministack server, CreateDomain+ spawns a real opensearchproject/opensearch container and DescribeDomain+ returns its endpoint. Verify cluster health responds."""+ import urllib.request+ import json as _json++ o = _client()+ name = f"dp-{_uid()}"+ rec = o.create_domain(DomainName=name)["DomainStatus"]+ try:+ endpoint = rec["Endpoint"]+ if "ministack.local" in endpoint:+ pytest.skip("dataplane returned stub endpoint — Docker not available on test host")+ url = f"http://{endpoint}/_cluster/health"+ last_err = None+ for _ in range(60):+ try:+ body = _json.loads(urllib.request.urlopen(url, timeout=1).read())+ assert body["status"] in ("green", "yellow")+ return+ except Exception as e:+ last_err = e+ time.sleep(1)+ pytest.fail(f"cluster never became healthy: {last_err!r}")+ finally:+ o.delete_domain(DomainName=name)diff --git a/tests/test_organizations.py b/tests/test_organizations.pynew file mode 100644index 00000000..1059b15e--- /dev/null+++ b/tests/test_organizations.py@@ -0,0 +1,83 @@+import boto3+import pytest+from botocore.exceptions import ClientError++ENDPOINT = "http://localhost:4566"+REGION = "us-east-1"+++def _client(service, account="test"):+ return boto3.client(service, endpoint_url=ENDPOINT, region_name=REGION,+ aws_access_key_id=account, aws_secret_access_key="test")+++def _client_for(account):+ return _client("organizations", account=account)++[email protected](scope="module")+def orgs():+ return _client("organizations")+++def test_organizations_describe_organization(orgs):+ org = orgs.describe_organization()["Organization"]+ assert org["Id"].startswith("o-")+ assert org["FeatureSet"] == "ALL"+ assert org["Arn"].startswith("arn:aws:organizations::")+++def test_organizations_list_roots_singleton(orgs):+ roots = orgs.list_roots()["Roots"]+ assert len(roots) == 1+ assert roots[0]["Id"].startswith("r-")+ assert roots[0]["Name"] == "Root"+++def test_organizations_list_accounts_includes_master(orgs):+ accounts = orgs.list_accounts()["Accounts"]+ assert any(a["Id"] == "000000000000" for a in accounts)+++def test_organizations_describe_missing_account(orgs):+ with pytest.raises(ClientError) as exc:+ orgs.describe_account(AccountId="999999999999")+ assert exc.value.response["Error"]["Code"] == "AccountNotFoundException"+++def test_organizations_create_nested_ou_path():+ """Path field reflects parent chain — additive 2026-03 AWS field."""+ o = _client_for("333333333333")+ root_id = o.list_roots()["Roots"][0]["Id"]+ eng = o.create_organizational_unit(ParentId=root_id, Name="Engineering")["OrganizationalUnit"]+ backend = o.create_organizational_unit(ParentId=eng["Id"], Name="Backend")["OrganizationalUnit"]++ # boto3 1.38 deserialiser may not surface Path; verify via raw HTTP call.+ import json as _json+ import urllib.request as _r+ req = _r.Request(+ "http://localhost:4566/",+ data=_json.dumps({"OrganizationalUnitId": backend["Id"]}).encode(),+ headers={+ "X-Amz-Target": "AWSOrganizationsV20161128.DescribeOrganizationalUnit",+ "Content-Type": "application/x-amz-json-1.1",+ "Authorization": ("AWS4-HMAC-SHA256 Credential=333333333333/20260101/"+ "us-east-1/organizations/aws4_request, SignedHeaders=, Signature=x"),+ },+ )+ body = _json.loads(_r.urlopen(req).read())+ assert body["OrganizationalUnit"]["Path"] == "/Engineering/Backend/"++ o.delete_organizational_unit(OrganizationalUnitId=backend["Id"])+ o.delete_organizational_unit(OrganizationalUnitId=eng["Id"])+++def test_organizations_list_ous_for_parent():+ o = _client_for("444444444444")+ root_id = o.list_roots()["Roots"][0]["Id"]+ ou = o.create_organizational_unit(ParentId=root_id, Name="Sales")["OrganizationalUnit"]+ try:+ listed = o.list_organizational_units_for_parent(ParentId=root_id)["OrganizationalUnits"]+ assert any(x["Id"] == ou["Id"] for x in listed)+ finally:+ o.delete_organizational_unit(OrganizationalUnitId=ou["Id"])diff --git a/tests/test_waf_v1.py b/tests/test_waf_v1.pynew file mode 100644index 00000000..a43458fe--- /dev/null+++ b/tests/test_waf_v1.py@@ -0,0 +1,81 @@+"""Tests for WAF Classic + WAF Regional v1 stub.++The v1 stub returns AWS-shape-correct empty-state responses so that legacy+SDKs (Terraform, old CFN, JDK examples) targeting v1 don't get a 405.+For real WebACL state, callers should use wafv2.+"""++import boto3+import pytest+++def _client(service):+ return boto3.client(service, endpoint_url="http://localhost:4566",+ region_name="us-east-1",+ aws_access_key_id="test", aws_secret_access_key="test")++[email protected](scope="module")+def waf_regional():+ return _client("waf-regional")++[email protected](scope="module")+def waf_classic():+ return _client("waf")+++def test_waf_regional_list_web_acls_empty(waf_regional):+ r = waf_regional.list_web_acls(Limit=10)+ assert r["WebACLs"] == []+++def test_waf_regional_list_ip_sets_empty(waf_regional):+ r = waf_regional.list_ip_sets(Limit=10)+ assert r["IPSets"] == []+++def test_waf_regional_list_rules_empty(waf_regional):+ r = waf_regional.list_rules(Limit=10)+ assert r["Rules"] == []+++def test_waf_regional_get_change_token_returns_token(waf_regional):+ r = waf_regional.get_change_token()+ token = r["ChangeToken"]+ assert isinstance(token, str)+ assert len(token) >= 8+++def test_waf_regional_get_change_token_status_is_insync(waf_regional):+ token = waf_regional.get_change_token()["ChangeToken"]+ s = waf_regional.get_change_token_status(ChangeToken=token)+ assert s["ChangeTokenStatus"] == "INSYNC"+++def test_waf_regional_get_unknown_webacl_raises_not_found(waf_regional):+ from botocore.exceptions import ClientError+ with pytest.raises(ClientError) as exc:+ waf_regional.get_web_acl(WebACLId="never-existed")+ assert exc.value.response["Error"]["Code"] == "WAFNonexistentItemException"+++def test_waf_classic_list_web_acls_empty(waf_classic):+ """waf-classic shares the same v1 module — verify the second target prefix routes correctly."""+ r = waf_classic.list_web_acls(Limit=10)+ assert r["WebACLs"] == []+++def test_waf_classic_get_change_token(waf_classic):+ r = waf_classic.get_change_token()+ assert r["ChangeToken"]+++def test_waf_v1_does_not_collide_with_wafv2():+ """Sanity: wafv2 uses the real handler, v1 the stub. Listing on each+ targets distinct backends and must not cross-contaminate."""+ v1 = _client("waf-regional")+ v2 = _client("wafv2")+ # An empty wafv2 list still works alongside the v1 stub+ assert isinstance(v1.list_web_acls(Limit=5)["WebACLs"], list)+ assert isinstance(v2.list_web_acls(Scope="REGIONAL", Limit=5)["WebACLs"], list)