diff --git a/.github/workflows/deploy_fastapi_backend.yml b/.github/workflows/deploy_fastapi_backend.yml index a3691f98..502a9eb8 100644 --- a/.github/workflows/deploy_fastapi_backend.yml +++ b/.github/workflows/deploy_fastapi_backend.yml @@ -66,13 +66,13 @@ jobs: - name: Setup Docker uses: docker/setup-buildx-action@v1 - - name: Setup Docker Buildx - run: | - docker buildx create --use + # - name: Setup Docker Buildx + # run: | + # docker buildx create --use - name: Build Docker Image run: | - docker buildx build --platform linux/arm64 -t fastapi-lambda-image:${{ github.sha }} -f backend/docker/lambda.Dockerfile . --load + docker build -t fastapi-lambda-image:${{ github.sha }} -f backend/docker/lambda.Dockerfile . --load - name: Login to ECR run: | diff --git a/backend/docker/Dockerfile b/backend/docker/Dockerfile index a02fda22..f23435a0 100644 --- a/backend/docker/Dockerfile +++ b/backend/docker/Dockerfile @@ -1,5 +1,5 @@ # Pull base image -FROM python:3.10.12-slim-buster +FROM python:3.10.12-slim-buster as build-image # Set environment variables ENV PYTHONDONTWRITEBYTECODE 1 @@ -9,7 +9,7 @@ ENV PYTHONUNBUFFERED 1 WORKDIR var/task/Model # Install system dependencies -RUN apt-get update && apt-get install -y netcat-openbsd +RUN #apt-get update && apt-get install -y netcat-openbsd # Install python dependencies COPY ./backend/requirements/base.txt ./backend/requirements/base.txt @@ -17,8 +17,20 @@ RUN pip install --upgrade pip # Install and clean up temp caches RUN pip install -r backend/requirements/base.txt && rm -rf /root/.cache -# When running locally, we need boto3 -RUN pip install boto3 +# Since we are not using a base AWS image, there is some additional setup required. We need to set up the runtime +# interface client +# https://docs.aws.amazon.com/lambda/latest/dg/python-image.html#python-image-clients +# Additionally install the AWS Lambda RIC +RUN pip install awslambdaric + +# Second stage: "runtime-image" +FROM 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 project files COPY ./backend/ ./backend @@ -33,5 +45,7 @@ COPY ./model_data/epc_attributes/ ./model_data/epc_attributes/ COPY ./datatypes/ ./datatypes/ COPY ./utils/ ./utils/ -# command to run on container start -CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "8000"] +# Set the ENTRYPOINT to the AWS Lambda RIC and CMD to your function handler +ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ] +# Define the handler location +CMD ["backend.app.main.handler"] \ No newline at end of file