From aea7251107ed1e0136b83e5ba6421b71ab0ee98b Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Thu, 21 May 2026 14:21:50 +0000 Subject: [PATCH] added files for landlord_overrides --- applications/landlord_overrides/Dockerfile | 34 +++++++++++++++++++ applications/landlord_overrides/handler.py | 9 +++++ .../local_handler/.env.local.example | 5 +++ .../local_handler/docker-compose.yml | 9 +++++ .../local_handler/invoke_local_lambda.py | 16 +++++++++ .../local_handler/run_local.sh | 12 +++++++ .../landlord_overrides/requirements.txt | 4 +++ 7 files changed, 89 insertions(+) create mode 100644 applications/landlord_overrides/Dockerfile create mode 100644 applications/landlord_overrides/handler.py create mode 100644 applications/landlord_overrides/local_handler/.env.local.example create mode 100644 applications/landlord_overrides/local_handler/docker-compose.yml create mode 100755 applications/landlord_overrides/local_handler/invoke_local_lambda.py create mode 100755 applications/landlord_overrides/local_handler/run_local.sh create mode 100644 applications/landlord_overrides/requirements.txt diff --git a/applications/landlord_overrides/Dockerfile b/applications/landlord_overrides/Dockerfile new file mode 100644 index 00000000..ef19f379 --- /dev/null +++ b/applications/landlord_overrides/Dockerfile @@ -0,0 +1,34 @@ +FROM public.ecr.aws/lambda/python:3.11 + +# Postgres host/port/database are baked into the image at build time from +# the deploy workflow's --build-arg values (GitHub Actions DEV_DB_* secrets), +# mirroring backend/postcode_splitter/handler/Dockerfile. They map onto the +# POSTGRES_* names PostgresConfig.from_env reads. Username/password are NOT +# baked in -- Terraform injects those as Lambda env vars from Secrets Manager. +ARG DEV_DB_HOST +ARG DEV_DB_PORT +ARG DEV_DB_NAME + +ENV POSTGRES_HOST=${DEV_DB_HOST} +ENV POSTGRES_PORT=${DEV_DB_PORT} +ENV POSTGRES_DATABASE=${DEV_DB_NAME} + +WORKDIR /var/task + +COPY applications/postcode_splitter/requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the layered source the handler imports from. The new splitter pulls +# only DDD-shaped packages — no pandas, no legacy backend/. +COPY domain/ domain/ +COPY infrastructure/ infrastructure/ +COPY orchestration/ orchestration/ +COPY repositories/ repositories/ +COPY utilities/ utilities/ +COPY applications/ applications/ + +# Place the handler at the Lambda task root so the runtime can resolve +# ``main.handler`` without an extra package prefix. +COPY applications/landlord_overrides/handler.py /var/task/main.py + +CMD ["main.handler"] diff --git a/applications/landlord_overrides/handler.py b/applications/landlord_overrides/handler.py new file mode 100644 index 00000000..f998da1d --- /dev/null +++ b/applications/landlord_overrides/handler.py @@ -0,0 +1,9 @@ +from typing import Any + + +def handler( + body: dict[str, Any], + context: Any, +) -> dict[str, list[str]]: + print("hello world") + return {"hello world": ["hello world"]} diff --git a/applications/landlord_overrides/local_handler/.env.local.example b/applications/landlord_overrides/local_handler/.env.local.example new file mode 100644 index 00000000..a78a797f --- /dev/null +++ b/applications/landlord_overrides/local_handler/.env.local.example @@ -0,0 +1,5 @@ +POSTGRES_HOST= +POSTGRES_PORT=5432 +POSTGRES_USERNAME= +POSTGRES_PASSWORD= +POSTGRES_DATABASE= \ No newline at end of file diff --git a/applications/landlord_overrides/local_handler/docker-compose.yml b/applications/landlord_overrides/local_handler/docker-compose.yml new file mode 100644 index 00000000..d217ded6 --- /dev/null +++ b/applications/landlord_overrides/local_handler/docker-compose.yml @@ -0,0 +1,9 @@ +services: + landlord_overrides: + build: + context: ../../../ + dockerfile: applications/landlord_overrides/Dockerfile + ports: + - "9002:8080" + env_file: + - .env.local diff --git a/applications/landlord_overrides/local_handler/invoke_local_lambda.py b/applications/landlord_overrides/local_handler/invoke_local_lambda.py new file mode 100755 index 00000000..4514495f --- /dev/null +++ b/applications/landlord_overrides/local_handler/invoke_local_lambda.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +import json +import requests + +HOST = "localhost" +PORT = "9002" + +LAMBDA_URL = f"http://{HOST}:{PORT}/2015-03-31/functions/function/invocations" + +payload = {"Records": [{"body": json.dumps({})}]} + +response = requests.post(LAMBDA_URL, json=payload) + +print("Status code:", response.status_code) +print("Response:") +print(response.text) diff --git a/applications/landlord_overrides/local_handler/run_local.sh b/applications/landlord_overrides/local_handler/run_local.sh new file mode 100755 index 00000000..345b60ee --- /dev/null +++ b/applications/landlord_overrides/local_handler/run_local.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "$0")" + +if [ ! -f .env.local ]; then + cp .env.local.example .env.local + echo "Created .env.local from the template — fill it in, then re-run." >&2 + exit 1 +fi + +docker compose build --no-cache +docker compose up --force-recreate diff --git a/applications/landlord_overrides/requirements.txt b/applications/landlord_overrides/requirements.txt new file mode 100644 index 00000000..6a85a255 --- /dev/null +++ b/applications/landlord_overrides/requirements.txt @@ -0,0 +1,4 @@ +boto3 +pydantic +sqlmodel +psycopg2-binary