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
docs: clarify contributor guidance (#1784)
Johannes Grumböck8679e95c95ce
diff --git a/AGENTS.md b/AGENTS.mdnew file mode 100644index 00000000..7b148eba--- /dev/null+++ b/AGENTS.md@@ -0,0 +1,75 @@+# AGENTS.md++Instructions for AI coding agents working in MiniStack. Read `CONTRIBUTING.md`+before changing a service; it has the contribution process and examples.++## Where to work++- `ministack/app.py` owns service registration, dispatch, and reset.+- `ministack/core/router.py` detects services; `ministack/core/responses.py`+ contains shared response and account/region helpers.+- `ministack/services/` contains service implementations. Start with the+ existing service module or package and its neighboring code.+- `tests/test_<service>.py` is the usual test location; established services+ may have several test files. `tests/conftest.py` holds client fixtures and+ the `_SERIAL_TESTS` list.++## Before changing behavior++- New AWS services and infrastructure changes (Dockerfiles, CI workflows,+ `pyproject.toml`, dependencies) need a scoped GitHub issue before code is+ written. Check for overlapping work. Follow the scope agreed in the issue.+- Keep additions focused on operations needed by a real use case. Do not add+ speculative API coverage or operations that return placeholder results.+- Check the behavior and wire format against available evidence. Never claim+ behavior was validated against AWS unless it was actually run against a real+ AWS account. Label the evidence precisely as a real AWS observation (record+ region and account context when relevant), official AWS documentation,+ botocore service model inspection, existing tests or code, or inference;+ documentation, model inspection, and tests are not AWS validation. Match+ errors, status codes, and retry behavior.+- If AWS has one fixed behavior, implement that behavior directly rather than+ adding a MiniStack setting. Add configuration only for choices MiniStack+ itself must make.++## Service contracts++- For routing and response formats, inspect the existing handler,+ `core/router.py`, and the relevant botocore model. Some services support+ multiple protocols. Preserve the wire format used by the operation being+ changed; see `CONTRIBUTING.md` for examples.+- A new service needs an entry in `SERVICE_REGISTRY` in `app.py` and the+ routing needed in `core/router.py`. Follow an established service's module+ layout when extending it; not every helper or submodule needs its own+ routing pattern.+- Every registered service module, including registered submodules, must+ define `get_state()`, `load_persisted_state(data)`, and `reset()`. The+ registry and `tests/test_persistence.py` enforce this contract.+- Keep resources isolated by account and region where AWS does. Follow the+ existing scoped-state helpers and check that persistence saves all tenants,+ not only the current request's tenant.+- Keep AWS SDK clients out of service implementations. Use them in tests or+ for shape inspection during development. Follow nearby code for blocking+ Docker calls and avoid adding service locks without checking reentrant calls.++## Working and validation++- Python 3.10+ is supported; CI uses 3.13. Install test dependencies with+ `uv pip install --system -e ".[test]" -r requirements.txt`.+- Start MiniStack with `python -m hypercorn ministack.app:app --bind 0.0.0.0:4566`;+ check `http://localhost:4566/_ministack/health`. Most tests+ require the server at `localhost:4566`.+- Run the relevant test file, then `pytest tests/` when routing, registry, or+ service behavior changed. Run `ruff check ministack/`, the CI lint gate.+- Tests that alter global server state or depend on ordering belong in+ `_SERIAL_TESTS` in `tests/conftest.py`; keep them out of parallel runs.++## Before opening a PR++- Update the supported-services table in `README.md` for a new service and+ follow the existing `CHANGELOG.md` format for user-facing changes.+- Preserve explanatory dependency comments in `pyproject.toml` when changing+ dependencies. Avoid new lint suppressions without a reason.+- Keep each PR focused. Describe every behavior change in the diff, how it+ was validated, and any issue that the change fulfills.+- Confirm the relevant tests, broader suite when needed, and lint pass.diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex ef157d77..85b08367 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -18,7 +18,7 @@ ministack/│ └── cognito.py # example of a two-client service file├── tests/│ ├── conftest.py # pytest fixtures (boto3 clients)-│ └── test_services.py # all integration tests+│ └── test_<service>.py # integration tests by service├── Dockerfile├── pyproject.toml└── CHANGELOG.md@@ -47,7 +47,7 @@ A maintainer will confirm the scope, flag overlap with existing work, and point## Adding a New Service-Every service follows the same 4-step pattern:+For a new service, follow these steps:### 1. Create `ministack/services/myservice.py`@@ -58,16 +58,14 @@ JSON-based API via X-Amz-Target.Supports: OperationOne, OperationTwo, ..."""+import copyimport jsonimport logging-from ministack.core.responses import json_response, error_response_json, new_uuid+from ministack.core.responses import AccountRegionScopedDict, json_response, error_response_jsonlogger = logging.getLogger("myservice")-ACCOUNT_ID = "000000000000"-REGION = "us-east-1"--_state: dict = {} # in-memory storage+_state = AccountRegionScopedDict() # for account- and region-scoped resourcesasync def handle_request(method, path, headers, body, query_params):@@ -98,15 +96,32 @@ def _operation_two(data):return json_response({})+def get_state():+ return {"state": copy.deepcopy(_state)}+++def load_persisted_state(data):+ if data:+ _state.update(data.get("state", {}))++def reset():_state.clear()```-**Protocol guide:**+**Protocol guide:** Check the botocore service model and an existing handler+before choosing how to dispatch an operation.++- **JSON:** Commonly uses `X-Amz-Target` and the shared `json_response` /+ `error_response_json` helpers.+- **Query:** Uses `Action` in the URL or a form-encoded POST body and returns+ XML; verify response shapes against botocore with+ `Loader().load_service_model()`.+- **S3:** Uses a REST-style API with XML responses and dispatches by method,+ path, and subresource.-- JSON services (DynamoDB, SecretsManager, Glue, Athena, Cognito, etc.) — use `json_response` / `error_response_json`, route via `X-Amz-Target`-- XML/Query services (S3, SQS, SNS, IAM, STS, RDS, ElastiCache, EC2) — build XML responses, route via `Action` query param; use `_xml(status, root_tag, inner)` pattern; verify field names against botocore shapes via `Loader().load_service_model()`-- REST services (Lambda, ECS, Route53) — route via URL path+Some services support more than one protocol, so follow the operation's actual+wire format.### 2. Register in `ministack/app.py`@@ -143,7 +158,7 @@ def mysvc():return make_client("myservice")```-### 5. Add tests to `tests/test_services.py`+### 5. Add tests to `tests/test_myservice.py````pythondef test_myservice_operation_one(mysvc):@@ -178,10 +193,9 @@ pytest tests/ -v -k "cognito"## Code Conventions-- **One file per service** — keep everything for a service in `ministack/services/myservice.py`- **Imports** — always `from ministack.core.responses import ...`, never `from core.responses import ...`-- **In-memory state** — use module-level dicts (`_things: dict = {}`)-- **reset()** — every service must expose a `reset()` that clears all module-level state; it's called by `/_ministack/reset`+- **In-memory state** — scope resources by account and region where AWS does; follow the existing `AccountRegionScopedDict` pattern+- **State contract** — every registered service module defines `get_state()`, `load_persisted_state(data)`, and `reset()`; `tests/test_persistence.py` checks this, and `/_ministack/reset` calls `reset()`- **No external AWS deps** — no `boto3`, `botocore`, or `aws-sdk` in service code- **Minimal dependencies** — `duckdb` and `docker` are optional; guard with `try/except ImportError`- **Error responses** — match real AWS error codes and HTTP status codes as closely as possible@@ -196,6 +210,7 @@ pytest tests/ -v -k "cognito"- [ ] Detection patterns added to `ministack/core/router.py`- [ ] Fixture added to `tests/conftest.py`- [ ] Tests added and passing (`pytest tests/ -v`)+- [ ] Registered modules expose `get_state()`, `load_persisted_state(data)`, and `reset()`- [ ] Linting passes (`ruff check ministack/`)- [ ] Service added to the table in `README.md`- [ ] Entry added to `CHANGELOG.md`