From 8507696adb8fb3bcdb5e7510ddadc2d28030e387 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Wed, 6 May 2026 14:54:06 -0700 Subject: [PATCH] infra(spikes): add Flask callback receiver for LIT-2888 EC2 spike 5-line Flask app on port 3333 that logs callbacks from EC2 user-data and SSM RunCommand. Used by the EC2 provisioning spike to time when boot and hydrate callbacks arrive. --- infra/spikes/callback_receiver.py | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 infra/spikes/callback_receiver.py diff --git a/infra/spikes/callback_receiver.py b/infra/spikes/callback_receiver.py new file mode 100644 index 00000000000..d596d2d1988 --- /dev/null +++ b/infra/spikes/callback_receiver.py @@ -0,0 +1,48 @@ +""" +Flask callback receiver for the EC2 provisioning spike (LIT-2888). + +Listens on port 3333 for POST /spike. Logs every callback with timestamp + body. +Used in tandem with ngrok to give EC2 instances a public HTTPS URL to hit. + +Run: + uv run python infra/spikes/callback_receiver.py +""" + +import json +import sys +import time +from flask import Flask, request + +app = Flask(__name__) + +# In-memory log of received callbacks. Useful when the spike script polls +# the receiver to confirm both `phase=boot` and `phase=hydrate` arrived. +CALLBACKS: list = [] + + +@app.post("/spike") +def spike() -> tuple[dict, int]: + body = request.get_json(silent=True) or {} + entry = {"received_at": time.time(), "body": body} + CALLBACKS.append(entry) + print( + f"[{time.strftime('%H:%M:%S')}] callback: {json.dumps(body)}", + file=sys.stderr, + flush=True, + ) + return {"ok": True}, 200 + + +@app.get("/callbacks") +def list_callbacks() -> dict: + """Return all callbacks received so far. The spike script polls this.""" + return {"callbacks": CALLBACKS} + + +@app.get("/health") +def health() -> dict: + return {"ok": True} + + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=3333, debug=False)