diff --git a/backend/docker/lambda.Dockerfile b/backend/docker/lambda.Dockerfile index 73d08e09..41b7db34 100644 --- a/backend/docker/lambda.Dockerfile +++ b/backend/docker/lambda.Dockerfile @@ -13,7 +13,7 @@ ENV PYTHONUNBUFFERED 1 WORKDIR /var/task/Model # Install system dependencies -RUN apt-get update && apt-get install -y gcc g++ gfortran libgfortran-9-dev liblapack-dev libamd2 libcholmod3 \ +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 # Compile CBC for arm64 diff --git a/run_lambda_local.sh b/run_lambda_local.sh new file mode 100644 index 00000000..b6bba656 --- /dev/null +++ b/run_lambda_local.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Set up constants +IMAGE_NAME="fastapi-lambda-image" +TAG="test" +PORT="8000" +RIE_PATH="~/.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" + +# Step 1: Download the AWS Lambda Runtime Interface Emulator if it doesn't exist +if [ ! -f "$RIE_PATH/aws-lambda-rie" ]; then + echo "Downloading AWS Lambda Runtime Interface Emulator..." + mkdir -p $RIE_PATH + curl -Lo $RIE_PATH/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie-arm64 + chmod +x $RIE_PATH/aws-lambda-rie +fi + +# Step 2: Build the Docker image +echo "Building Docker image..." +docker build -t $IMAGE_NAME:$TAG -f backend/docker/lambda.Dockerfile . + +# Step 3: Run the Docker image with the emulator, .env file, and AWS credentials +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 \ + -p $PORT:8080 \ + --entrypoint $DOCKER_ENTRYPOINT \ + $IMAGE_NAME:$TAG $DOCKER_CMD) + +# Output information +echo "Docker container is running. Use the following command to send a request:" +echo "curl \"http://localhost:$PORT/2015-03-31/functions/function/invocations\" -d '{}'" + +# Optional: If you want the script to stop the Docker container after you press a key, you can uncomment the next lines. +# echo "Press any key to stop the Docker container..." +# read -n 1 -s -r +# docker kill $CONTAINER_ID