Merge pull request #164 from Hestia-Homes/main

revert back to x86
This commit is contained in:
KhalimCK 2023-08-24 20:13:04 +01:00 committed by GitHub
commit 1a3c09f0a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 21 deletions

View file

@ -120,7 +120,27 @@ Now you can run the script with
./run_lambda_local.sh
```
Then run the script with the following command:
In order to make a request to it, there is a specific format the request must be in, to
emuate lambda. If using postman, the url you want is `http://localhost:8000/2015-03-31/functions/function/invocations`
and you need to pass a body like this:
```json
{
"httpMethod": "POST",
"body": "{\"portfolio_id\": 4, \"housing_type\": \"Private\", \"goal\": \"Increase EPC\", \"goal_value\": \"C\", \"trigger_file_path\": \"2/4/portfolio_plan_properties-20230724T093542483Z.csv\"}",
"path": "/v1/plan/trigger",
"resource": "/",
"headers": {
"Accept": "*/*",
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_TOKEN_HERE",
"x-api-key": "YOUR_API_KEY_HERE"
},
"requestContext": {},
"multiValueQueryStringParameters": null
}
```
```commandline

View file

@ -3,7 +3,7 @@
# https://python-mip.readthedocs.io/en/latest/install.html
# Pull base image
FROM arm64v8/python:3.10.12-slim-bullseye as build-image
FROM arm64v8/python:3.10.12-slim-buster as build-image
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
@ -13,14 +13,7 @@ ENV PYTHONUNBUFFERED 1
WORKDIR /var/task/Model
# Install system dependencies
RUN apt-get update && apt-get install -y make gcc g++ gfortran libgfortran-9-dev liblapack-dev libamd2 libcholmod3 \
libmetis-dev libsuitesparse-dev libnauty2-dev git wget pkgconf
# Compile CBC for arm64
RUN mkdir -p ~/build && cd ~/build \
&& wget -nH https://raw.githubusercontent.com/coin-or/coinbrew/master/coinbrew \
&& bash coinbrew fetch Cbc@master --no-prompt \
&& bash coinbrew build Cbc@master --no-prompt --prefix=/home/root/prog/ --tests=none --enable-cbc-parallel --enable-relocatable
# RUN apt-get update && apt-get install -y netcat-openbsd
# Install python dependencies
COPY ./backend/requirements/base.txt ./backend/requirements/base.txt
@ -31,18 +24,13 @@ RUN pip install --upgrade pip \
RUN pip install awslambdaric
# Second stage: "runtime-image"
FROM arm64v8/python:3.10.12-slim-bullseye
FROM arm64v8/python:3.10.12-slim-buster
# Set work directory to the root of your project
WORKDIR /var/task/Model
# Copy the python dependencies from the build-image
COPY --from=build-image /usr/local/lib/python3.10/site-packages/ /usr/local/lib/python3.10/site-packages/
COPY --from=build-image /home/root/prog/lib/ /usr/local/lib/
# Set environment variable for mip to use custom CBC binaries
ENV PMIP_CBC_LIBRARY="/usr/local/lib/libCbcSolver.so"
ENV LD_LIBRARY_PATH="/usr/local/lib/":$LD_LIBRARY_PATH
# Copy project files
COPY ./backend/ ./backend

View file

@ -4,11 +4,11 @@
IMAGE_NAME="fastapi-lambda-image"
TAG="test"
PORT="8000"
RIE_PATH="~/.aws-lambda-rie"
RIE_DIR="$HOME/.aws-lambda-rie"
DOCKER_ENTRYPOINT="$RIE_PATH/aws-lambda-rie"
DOCKER_CMD="/usr/local/bin/python -m awslambdaric backend.app.main.handler"
ENV_FILE_PATH="backend/.env"
AWS_CREDENTIALS_PATH="~/.aws/credentials"
AWS_CREDENTIALS_PATH="$HOME/.aws/credentials"
# Step 1: Download the AWS Lambda Runtime Interface Emulator if it doesn't exist
if [ ! -f "$RIE_PATH/aws-lambda-rie" ]; then
@ -27,9 +27,9 @@ echo "Starting the Docker container..."
CONTAINER_ID=$(docker run -d \
--env-file $ENV_FILE_PATH \
-v $AWS_CREDENTIALS_PATH:/root/.aws/credentials \
-v $RIE_PATH:/aws-lambda \
-v "$RIE_DIR:/aws-lambda" \
-p $PORT:8080 \
--entrypoint $DOCKER_ENTRYPOINT \
--entrypoint "/aws-lambda/aws-lambda-rie" \
$IMAGE_NAME:$TAG $DOCKER_CMD)
# Output information

View file

@ -3,7 +3,7 @@ service: fastapi-lambda
provider:
name: aws
region: eu-west-2
architecture: arm64
architecture: x86_64
environment:
API_KEY: ${env:API_KEY}
ENVIRONMENT: ${env:ENVIRONMENT}