mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
define dockerfile (with print hello world)
This commit is contained in:
parent
bfe81d4cfe
commit
6a7f99d6fa
5 changed files with 63 additions and 52 deletions
|
|
@ -1,15 +0,0 @@
|
|||
FROM public.ecr.aws/lambda/python:3.11
|
||||
|
||||
# Set working directory (Lambda task root)
|
||||
WORKDIR /var/task
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Copy application code
|
||||
# -----------------------------
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Lambda handler
|
||||
# -----------------------------
|
||||
CMD ["handler.handler"]
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
import json
|
||||
from typing import Mapping, Any
|
||||
from io import BytesIO
|
||||
|
||||
from backend.condition.condition_trigger_request import ConditionTriggerRequest
|
||||
from backend.condition.lookups.uprn_lookup_s3 import UprnLookupS3
|
||||
from backend.condition.processor import process_file
|
||||
from utils.logger import setup_logger
|
||||
from utils.s3 import read_io_from_s3
|
||||
|
||||
|
||||
logger = setup_logger()
|
||||
|
||||
|
||||
def handler(event: Mapping[str, Any], context: Any) -> None:
|
||||
uprn_lookup = UprnLookupS3(
|
||||
bucket="", key=""
|
||||
) # TODO: replace with postgres implementation
|
||||
|
||||
for record in event.get("Records", []):
|
||||
try:
|
||||
body_dict = json.loads(record["body"])
|
||||
payload = ConditionTriggerRequest.model_validate(body_dict)
|
||||
|
||||
file_bytes: BytesIO = read_io_from_s3(
|
||||
bucket_name=payload.trigger_file_bucket,
|
||||
file_key=payload.trigger_file_key,
|
||||
)
|
||||
|
||||
process_file(
|
||||
file_stream=file_bytes,
|
||||
file_type=payload.file_type,
|
||||
uprn_lookup=uprn_lookup,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to process record: {e}")
|
||||
25
backend/condition/handler/Dockerfile
Normal file
25
backend/condition/handler/Dockerfile
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
FROM public.ecr.aws/lambda/python:3.11
|
||||
# FROM python:3.11.10-bullseye
|
||||
|
||||
# Set working directory (Lambda task root)
|
||||
WORKDIR /var/task
|
||||
|
||||
# -----------------------------
|
||||
# Copy requirements FIRST (for Docker layer caching)
|
||||
# -----------------------------
|
||||
COPY backend/condition/handler/requirements.txt .
|
||||
|
||||
# Install dependencies into Lambda runtime
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# -----------------------------
|
||||
# Copy application code
|
||||
# -----------------------------
|
||||
COPY utils/ utils/
|
||||
COPY backend/condition/ backend/condition/
|
||||
COPY backend/__init__.py backend/__init__.py
|
||||
|
||||
# -----------------------------
|
||||
# Lambda handler
|
||||
# -----------------------------
|
||||
CMD ["backend/condition/handler/handler.handler"]
|
||||
38
backend/condition/handler/handler.py
Normal file
38
backend/condition/handler/handler.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import json
|
||||
from typing import Mapping, Any
|
||||
from io import BytesIO
|
||||
|
||||
from backend.condition.condition_trigger_request import ConditionTriggerRequest
|
||||
from backend.condition.lookups.uprn_lookup_s3 import UprnLookupS3
|
||||
from backend.condition.processor import process_file
|
||||
from utils.logger import setup_logger
|
||||
from utils.s3 import read_io_from_s3
|
||||
|
||||
|
||||
logger = setup_logger()
|
||||
|
||||
|
||||
def handler(event: Mapping[str, Any], context: Any) -> None:
|
||||
print("hello world")
|
||||
# uprn_lookup = UprnLookupS3(
|
||||
# bucket="", key=""
|
||||
# ) # TODO: replace with postgres implementation
|
||||
|
||||
# for record in event.get("Records", []):
|
||||
# try:
|
||||
# body_dict = json.loads(record["body"])
|
||||
# payload = ConditionTriggerRequest.model_validate(body_dict)
|
||||
|
||||
# file_bytes: BytesIO = read_io_from_s3(
|
||||
# bucket_name=payload.trigger_file_bucket,
|
||||
# file_key=payload.trigger_file_key,
|
||||
# )
|
||||
|
||||
# process_file(
|
||||
# file_stream=file_bytes,
|
||||
# file_type=payload.file_type,
|
||||
# uprn_lookup=uprn_lookup,
|
||||
# )
|
||||
|
||||
# except Exception as e:
|
||||
# logger.error(f"Failed to process record: {e}")
|
||||
Loading…
Add table
Reference in a new issue