From 058194fc14128302708e8ed880110ef13b3ebd35 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Fri, 1 Sep 2023 12:06:14 +0100 Subject: [PATCH] working on dockerfile and handler and added new s3 bucket --- infrastructure/terraform/main.tf | 6 ++++++ .../Dockerfiles/Dockerfile.prediction.lambda | 16 +++++++++------- .../handlers/predictions_app.py | 10 ++++++++-- .../requirements/predictions/predictions.txt | 2 ++ 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/infrastructure/terraform/main.tf b/infrastructure/terraform/main.tf index a90c4a78..5f623313 100644 --- a/infrastructure/terraform/main.tf +++ b/infrastructure/terraform/main.tf @@ -108,6 +108,12 @@ module "retrofit_sap_predictions" { allowed_origins = var.allowed_origins } +module "retrofit_sap_data" { + source = "./modules/s3" + bucketname = "retrofit-data-${var.stage}" + allowed_origins = var.allowed_origins +} + # Set up the route53 record for the API module "route53" { diff --git a/model_data/simulation_system/Dockerfiles/Dockerfile.prediction.lambda b/model_data/simulation_system/Dockerfiles/Dockerfile.prediction.lambda index bd7479e6..95da89c4 100644 --- a/model_data/simulation_system/Dockerfiles/Dockerfile.prediction.lambda +++ b/model_data/simulation_system/Dockerfiles/Dockerfile.prediction.lambda @@ -1,20 +1,22 @@ FROM public.ecr.aws/lambda/python:3.10 # Set the working directory -WORKDIR ${LAMBDA_TASK_ROOT} +WORKDIR ${LAMBDA_TASK_ROOT}/simulation_system # Install necessary build tools - required to test locally -# RUN yum install -y gcc python3-devel +RUN yum install -y gcc python3-devel # Install python packages COPY requirements/predictions/predictions.txt ./simulation_system/requirements.txt +COPY requirements/predictions/predictions-dev.txt ./simulation_system/requirements.txt RUN pip install --no-cache-dir -r ./simulation_system/requirements.txt # Copy the project code to the working directory -COPY ./core ./simulation_system/core -COPY ./MLModel ./simulation_system/MLModel -COPY ./predictions.py ./simulation_system/predictions.py -COPY ./handlers/predictions_app.py ./simulation_system/predictions_app.py +COPY ./core ./core +COPY ./MLModel ./MLModel +COPY ./predictions.py ./predictions.py +COPY ./handlers/predictions_app.py ./predictions_app.py +COPY ./__init__.py ./__init__.py # Run off a lambda trigger -CMD [ "simulation_system.predictions_app.handler" ] +CMD [ "predictions_app.handler" ] diff --git a/model_data/simulation_system/handlers/predictions_app.py b/model_data/simulation_system/handlers/predictions_app.py index 02b1673f..6e827388 100644 --- a/model_data/simulation_system/handlers/predictions_app.py +++ b/model_data/simulation_system/handlers/predictions_app.py @@ -1,14 +1,16 @@ import os import urllib.parse -from ..predictions import prediction +from predictions import prediction RUNTIME_ENVIRONMENT = os.environ.get("RUNTIME_ENVIRONMENT", "dev") -def handler(event, context): +def handler(): """ Take in event and trigger the prediction pipeline """ + print("HIHIHI") + event = {} # Assuming a file in a bucket landing for now? # Assuming we have a model to use @@ -43,3 +45,7 @@ def handler(event, context): except (Exception, KeyError, ValueError): print("Prediction failed") + + +if __name__ == "__main__": + handler() diff --git a/model_data/simulation_system/requirements/predictions/predictions.txt b/model_data/simulation_system/requirements/predictions/predictions.txt index 07b3e6d2..5d545ccb 100644 --- a/model_data/simulation_system/requirements/predictions/predictions.txt +++ b/model_data/simulation_system/requirements/predictions/predictions.txt @@ -1,3 +1,5 @@ autogluon==0.8.2 pandas==1.5.3 s3fs==2023.6.0 +seaborn==0.12.2 +matplotlib==3.7.2