mirror of
https://github.com/Hestia-Homes/ML.git
synced 2026-06-08 11:17:25 +00:00
Merge pull request #50 from Hestia-Homes/master
fixed docker file and added instructions
This commit is contained in:
commit
885f7ba977
3 changed files with 44 additions and 4 deletions
42
README.md
42
README.md
|
|
@ -40,3 +40,45 @@ For example, for the branch sap_change-dev, the prefix=SAP_CHANGE_DEV, and the f
|
|||
- {prefix}_DATA_BUCKET, is the name of the s3 data bucket where data to be scored by the model is stored
|
||||
- {prefix}_MODEL_BUCKET, is the name of the s3 bucket where the model is stored
|
||||
- {prefix}_PREDICTIONS_BUCKET, is the name of the s3 bucket where the predictions are stored
|
||||
|
||||
|
||||
# Building and Testing the Prediction Lambda Function Locally
|
||||
TODO: Generalise these instructions for the various different pipelines
|
||||
|
||||
This guide outlines the steps to build and test the Lambda function locally using Docker. These instructions assume you're working with a machine that has Docker installed.
|
||||
|
||||
### Prerequisites
|
||||
Docker: Make sure Docker is installed and running on your machine.
|
||||
AWS Credentials: Ensure you have AWS credentials set up on your local machine, typically stored
|
||||
in ~/.aws/credentials.
|
||||
Root Directory: All commands should be run from the root directory of the repository.
|
||||
Step-by-Step Guide
|
||||
1. Building the Docker Image
|
||||
First, navigate to the root directory of the repository. Open a terminal and execute the following
|
||||
2. command to build the Docker image:
|
||||
|
||||
```bash
|
||||
docker build -t sap_change -f deployment/Dockerfile.prediction.lambda .
|
||||
```
|
||||
|
||||
This will build a Docker image tagged as sap_change using the Dockerfile.prediction.lambda located
|
||||
in the deployment directory.
|
||||
|
||||
2. Running the Docker Image
|
||||
Once the image is built, you can run it using the following command:
|
||||
|
||||
```bash
|
||||
docker run -p 9000:8080 -v ~/.aws/credentials:/root/.aws/credentials:ro -e RUNTIME_ENVIRONMENT=dev sap_change
|
||||
```
|
||||
This command does the following:
|
||||
|
||||
Maps port 9000 on your local machine to port 8080 on the Docker container.
|
||||
Mounts your AWS credentials into the Docker container in read-only mode.
|
||||
Sets the RUNTIME_ENVIRONMENT variable to dev.
|
||||
3. Testing the Lambda Function
|
||||
To test the Lambda function, use the following curl command:
|
||||
|
||||
```json
|
||||
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"body": "{\"file_location\": \"s3://retrofit-data-dev/model_build_data/change_data/rdsap_full/test_data_with_id.parquet\", \"property_id\": 1, \"portfolio_id\": 4, \"created_at\": \"now\"}"'
|
||||
```
|
||||
This will send a POST request to the running Lambda function and pass in the required data as JSON.
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ ENV RUNTIME_ENVIRONMENT=${RUNTIME_ENVIRONMENT}
|
|||
RUN yum install -y gcc python3-devel
|
||||
|
||||
# Install python packages
|
||||
COPY modules/ml-pipeline/src/requirements/predictions/requirements.txt ./requirements.txt
|
||||
COPY modules/ml-pipeline/src/pipeline/requirements/predictions/requirements.txt ./requirements.txt
|
||||
RUN pip install --no-cache-dir -r ./requirements.txt
|
||||
|
||||
# Copy the project code
|
||||
|
|
@ -22,4 +22,4 @@ COPY deployment/handlers/prediction_app.py prediction_app.py
|
|||
# Get the model
|
||||
# RUN dvc pull -r ${RUNTIME_ENVIRONMENT}
|
||||
|
||||
CMD [ "prediction_handler.handler" ]
|
||||
CMD [ "prediction_app.handler" ]
|
||||
|
|
|
|||
|
|
@ -57,8 +57,6 @@ def handler(event, context):
|
|||
else event["body"]
|
||||
)
|
||||
|
||||
logger.info("Inside handler with body: " + str(body))
|
||||
|
||||
data_path = body["file_location"]
|
||||
property_id = body["property_id"]
|
||||
portfolio_id = body["portfolio_id"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue