Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

Replace uvicorn with hypercorn for HTTP/2 support (#369)

Akhil adigae52079498295
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 00a471f2..3cd1bc14 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -35,7 +35,7 @@ jobs:
- name: Start MiniStack
run: |
- REDIS_HOST=localhost python -m uvicorn ministack.app:app --host 0.0.0.0 --port 4566 &
+ REDIS_HOST=localhost python -m hypercorn ministack.app:app --bind 0.0.0.0:4566 --keep-alive 75 &
sleep 3
curl -sf http://localhost:4566/_ministack/health
diff --git a/Dockerfile b/Dockerfile
index ce40e58d..415b35e7 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,7 +1,7 @@
FROM python:3.12-alpine AS builder
RUN pip install --no-cache-dir --no-compile \
- uvicorn==0.30.6 \
+ hypercorn==0.18.0 \
"cbor2>=5.4.0" \
"defusedxml>=0.7" \
"docker>=7.0.0" \
@@ -33,7 +33,7 @@ WORKDIR /opt/ministack
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin/aws /usr/local/bin/aws
COPY --from=builder /usr/local/bin/aws_completer /usr/local/bin/aws_completer
-COPY --from=builder /usr/local/bin/uvicorn /usr/local/bin/uvicorn
+COPY --from=builder /usr/local/bin/hypercorn /usr/local/bin/hypercorn
COPY bin/awslocal /usr/local/bin/awslocal
RUN chmod +x /usr/local/bin/awslocal
@@ -67,4 +67,4 @@ EXPOSE 4566
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:4566/_ministack/health')" || exit 1
-ENTRYPOINT ["python", "-m", "uvicorn", "ministack.app:app", "--host", "0.0.0.0", "--port", "4566"]
+ENTRYPOINT ["python", "-m", "hypercorn", "ministack.app:app", "--bind", "0.0.0.0:4566", "--keep-alive", "75"]
diff --git a/README.md b/README.md
index a124ca9c..7e18d556 100644
--- a/README.md
+++ b/README.md
@@ -739,7 +739,7 @@ services:
ministack:
image: ministackorg/ministack:latest
container_name: infra_ministack
- entrypoint: ["python", "-m", "uvicorn", "ministack.app:app", "--host", "0.0.0.0", "--port", "4566"]
+ entrypoint: ["python", "-m", "hypercorn", "ministack.app:app", "--bind", "0.0.0.0:4566", "--keep-alive", "75"]
networks:
infra-network:
healthcheck:
diff --git a/ministack/app.py b/ministack/app.py
index 0fec07c1..15d20337 100644
--- a/ministack/app.py
+++ b/ministack/app.py
@@ -904,7 +904,8 @@ def _pid_file(port: int) -> str:
def main():
- import uvicorn
+ from hypercorn.config import Config as HypercornConfig
+ from hypercorn.asyncio import serve as hypercorn_serve
parser = argparse.ArgumentParser(description="MiniStack — Local AWS Service Emulator")
parser.add_argument("-d", "--detach", action="store_true", help="Run in the background (detached mode)")
@@ -943,10 +944,10 @@ def main():
# process; the OS reclaims it when the parent exits.
log_fh = open(log_file, "w")
proc = subprocess.Popen(
- [sys.executable, "-m", "uvicorn", "ministack.app:app",
- "--host", "0.0.0.0", "--port", str(port),
- "--log-level", LOG_LEVEL.lower(),
- "--timeout-keep-alive", "75"],
+ [sys.executable, "-m", "hypercorn", "ministack.app:app",
+ "--bind", f"0.0.0.0:{port}",
+ "--log-level", LOG_LEVEL.upper(),
+ "--keep-alive", "75"],
stdout=log_fh,
stderr=subprocess.STDOUT,
start_new_session=True,
@@ -980,18 +981,16 @@ def main():
def filter(self, record):
if LOG_LEVEL == "DEBUG":
return True
- msg = record.getMessage()
- return not any(p in msg for p in _HEALTH_PATHS)
-
- log_config = uvicorn.config.LOGGING_CONFIG.copy()
- log_config["loggers"] = log_config.get("loggers", {}).copy()
- log_config["filters"] = {"health_filter": {"()": lambda: _HealthLogFilter()}}
- access_logger = log_config["loggers"].get("uvicorn.access", {}).copy()
- access_logger["filters"] = ["health_filter"]
- log_config["loggers"]["uvicorn.access"] = access_logger
-
- uvicorn.run("ministack.app:app", host="0.0.0.0", port=port, log_level=LOG_LEVEL.lower(),
- timeout_keep_alive=75, log_config=log_config)
+ return not any(p in record.getMessage() for p in _HEALTH_PATHS)
+
+ logging.getLogger("hypercorn.access").addFilter(_HealthLogFilter())
+
+ config = HypercornConfig()
+ config.bind = [f"0.0.0.0:{port}"]
+ config.keep_alive_timeout = 75
+ config.loglevel = LOG_LEVEL.upper()
+
+ asyncio.run(hypercorn_serve(app, config))
finally:
_cleanup()
diff --git a/ministack/services/stepfunctions.py b/ministack/services/stepfunctions.py
index 93e2f7c1..7cfe9a9d 100644
--- a/ministack/services/stepfunctions.py
+++ b/ministack/services/stepfunctions.py
@@ -2318,7 +2318,7 @@ def _dispatch_aws_sdk_json(service_info, service_name, action, input_data):
# Service handlers are async def but perform no real I/O, so we can
# drive the coroutine synchronously — this avoids conflicts with the
- # already-running uvicorn event loop.
+ # already-running asyncio event loop.
coro = handler("POST", "/", headers, body, {})
try:
coro.send(None)
diff --git a/pyproject.toml b/pyproject.toml
index e5fa03ed..5d85ccfd 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -22,8 +22,7 @@ classifiers = [
"Topic :: Internet",
]
dependencies = [
- "uvicorn[standard]>=0.30.6",
- "httptools>=0.6.1",
+ "hypercorn>=0.18.0",
"pyyaml>=6.0",
"defusedxml>=0.7",
]
diff --git a/requirements.txt b/requirements.txt
index 3ae23993..4d745365 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,3 @@
-uvicorn[standard]==0.30.6
-httptools==0.6.1
+hypercorn==0.18.0
docker>=7.0.0
cbor2>=5.4.0