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
fix: hypercorn supervisor (#655)
Nahuel Nucera7e1b96c71e23
diff --git a/Dockerfile b/Dockerfileindex 7a298cb9..be241ea7 100644--- a/Dockerfile+++ b/Dockerfile@@ -73,4 +73,4 @@ EXPOSE 4566 2222HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \CMD python -c "import os,ssl,urllib.request as r; t=os.environ.get('USE_SSL','').strip().lower() in ('1','true','yes'); r.urlopen(('https' if t else 'http')+'://localhost:4566/_ministack/health',context=ssl._create_unverified_context() if t else None)" || exit 1-ENTRYPOINT ["python", "-m", "hypercorn", "ministack.app:app", "-c", "file:ministack/core/hypercorn_conf.py", "--bind", "0.0.0.0:4566", "--keep-alive", "75"]+ENTRYPOINT ["python", "-m", "ministack"]diff --git a/Dockerfile.full b/Dockerfile.fullindex ca4a3e6e..1a662e25 100644--- a/Dockerfile.full+++ b/Dockerfile.full@@ -88,4 +88,4 @@ EXPOSE 4566 2222HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \CMD python -c "import os,ssl,urllib.request as r; t=os.environ.get('USE_SSL','').strip().lower() in ('1','true','yes'); r.urlopen(('https' if t else 'http')+'://localhost:4566/_ministack/health',context=ssl._create_unverified_context() if t else None)" || exit 1-ENTRYPOINT ["python", "-m", "hypercorn", "ministack.app:app", "-c", "file:ministack/core/hypercorn_conf.py", "--bind", "0.0.0.0:4566", "--keep-alive", "75"]+ENTRYPOINT ["python", "-m", "ministack"]diff --git a/ministack/app.py b/ministack/app.pyindex 3c52320b..31c54c8e 100644--- a/ministack/app.py+++ b/ministack/app.py@@ -1539,14 +1539,21 @@ async def _handle_lifespan(scope, receive, send):_load_persisted_state()# Start the Transfer Family SFTP listener after persistence is# loaded (so any restored Transfer servers/users are visible to- # the SSH auth callback). Cheap no-op if asyncssh isn't- # installed or SFTP_ENABLED=0.- try:- from ministack.services import transfer+ # the SSH auth callback). When the user opts out via+ # SFTP_ENABLED=0 we skip importing the transfer module entirely+ # — its top-level `import asyncssh` pulls cryptography+OpenSSL+ # (~2–4 MiB of heap, plus C-level SSL contexts) which is pure+ # overhead for callers that aren't using Transfer Family.+ _sftp_env = os.environ.get("SFTP_ENABLED", "").strip().lower()+ if _sftp_env in ("0", "false", "no", "off"):+ logger.debug("SFTP_ENABLED=%s — skipping transfer module import.", _sftp_env)+ else:+ try:+ from ministack.services import transfer- await transfer.sftp_start()- except Exception as e:- logger.warning("Transfer SFTP startup failed: %s", e)+ await transfer.sftp_start()+ except Exception as e:+ logger.warning("Transfer SFTP startup failed: %s", e)# Start the EventBridge scheduler daemon explicitly. Module-import# autostart is gated by MINISTACK_TEST_NO_AUTOSTART so unit tests# don't race; lifespan.startup is the canonical place to spin it up.@@ -1585,7 +1592,17 @@ async def _handle_lifespan(scope, receive, send):def _stop_docker_containers():"""Stop all Docker containers managed by MiniStack (RDS, ECS, ElastiCache).- Uses container labels to find them — does not touch service state."""+ Uses container labels to find them — does not touch service state.++ Skip entirely if no Docker socket is available: importing the docker+ SDK (and its requests/urllib3/idna transitive deps) costs ~1 MiB of+ Python heap before we even know whether there's anything to clean.+ """+ sock = os.environ.get("DOCKER_HOST") or "unix:///var/run/docker.sock"+ if sock.startswith("unix://"):+ sock_path = sock[len("unix://"):]+ if not os.path.exists(sock_path):+ returntry:import docker@@ -1924,6 +1941,14 @@ def main():config.keep_alive_timeout = 75config.loglevel = LOG_LEVEL.upper()+ # USE_SSL=1 enables HTTPS — matches the behaviour previously provided+ # by ministack/core/hypercorn_conf.py when the entrypoint was the+ # hypercorn CLI. Self-signed cert auto-generated under TMPDIR, or BYO+ # via MINISTACK_SSL_CERT + MINISTACK_SSL_KEY.+ from ministack.core import tls as _tls+ if _tls.use_ssl_enabled():+ config.certfile, config.keyfile = _tls.resolve_tls_material()+asyncio.run(hypercorn_serve(app, config))finally:_cleanup()diff --git a/ministack/services/kms.py b/ministack/services/kms.pyindex a2be0dd9..d25ee435 100644--- a/ministack/services/kms.py+++ b/ministack/services/kms.py@@ -580,9 +580,18 @@ def _decrypt(data):rec = _resolve_key(embedded_id)if not rec:+ # AWS rule: NotFoundException only when the caller named a specific+ # KeyId that doesn't exist. A short/garbage ciphertext with no+ # explicit KeyId can't be parsed → InvalidCiphertextException.+ if key_id_from_data:+ return error_response_json(+ "NotFoundException",+ f"Key {key_id_from_data} not found",+ 400,+ )return error_response_json(- "NotFoundException",- "Unable to find the key for decryption",+ "InvalidCiphertextException",+ "",400,)err = _check_key_state(rec)