adding run local lambda and added make to system dependencies install

This commit is contained in:
Khalim Conn-Kowlessar 2023-08-24 17:26:22 +01:00
parent e64add45d6
commit 710b6b4648
2 changed files with 43 additions and 1 deletions

View file

@ -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

42
run_lambda_local.sh Normal file
View file

@ -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