fix(lambda): expose interactions.handler on the bootstrap stub (#59)
Some checks failed
Deploy / Deploy to prod (push) Has been cancelled

slack_interactions is configured for interactions.handler. A recreate that
reloads the stub zip must return 503 instead of failing at init.
This commit is contained in:
Adam Moussa 2026-09-16 20:52:14 +00:00 • committed by GitHub
parent f13d2e3ff1
commit 8dc3f71e6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 1 deletions

View file

@ -1,4 +1,8 @@
"""Bootstrap stub. GitHub Actions replaces this zip via update-function-code.""" """Bootstrap stub. GitHub Actions replaces this zip via update-function-code.
Keep a module for every Lambda handler setting in locals.functions. A recreate
must return 503 instead of failing at init because the entrypoint is missing.
"""
def handler(event, context): def handler(event, context):

View file

@ -0,0 +1,5 @@
"""Alias so slack_interactions (interactions.handler) can load the stub zip."""
from handler import handler
__all__ = ["handler"]

View file

@ -0,0 +1,34 @@
"""Stub zip must expose every Lambda handler name in locals.functions."""
from __future__ import annotations
import importlib.util
import sys
from pathlib import Path
STUB_DIR = Path(__file__).resolve().parents[1] / "terraform" / "bootstrap" / "stub"
def _load_file(module_name: str, path: Path):
spec = importlib.util.spec_from_file_location(module_name, path)
assert spec is not None and spec.loader is not None
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def test_stub_handler_modules_return_503() -> None:
handler_mod = _load_file("apm_stub_handler", STUB_DIR / "handler.py")
saved_handler = sys.modules.get("handler")
sys.modules["handler"] = handler_mod
try:
interactions_mod = _load_file("apm_stub_interactions", STUB_DIR / "interactions.py")
for module in (handler_mod, interactions_mod):
result = module.handler({}, None)
assert result["statusCode"] == 503
assert "NOT_DEPLOYED" in result["body"]
finally:
if saved_handler is None:
sys.modules.pop("handler", None)
else:
sys.modules["handler"] = saved_handler