Updated lamdba's dockerfile and serverless script to try and build the lambda from the docker image in ecr

This commit is contained in:
Khalim Conn-Kowlessar 2023-08-24 10:20:23 +01:00
parent 9a98503569
commit f27f6838cc
5 changed files with 30 additions and 38 deletions

View file

@ -1,5 +1,6 @@
model_data/local_data/*
backend/tests/*
backend/node_modules/*
recommendations/tests/*
model_data/tests/*
infrastructure/*

View file

@ -10,6 +10,11 @@ part of a larger application
# Folders
### backend/
This folder contains the code for the fastapi backend service, which provides an interface to
much of the functionality in this repository, for the frontend
### model_data/
This folder contains related to the reading and preparation of

View file

@ -59,6 +59,26 @@ FastAPI automatically generates interactive API documentation for your applicati
server and visit <yourlocalurl>/docs in your browser. Alternatively, you can go to
<yourlocalurl>/redoc to view the documentation in the ReDoc format.
## Building the backend docker image locally
To build the backend docker image locally, run the following command from the root of the project directory:
```commandline
docker build -t fastapi-lambda-image:latest -f backend/docker/lambda.Dockerfile .
```
To check the size of the resulting image, run the following command:
```bash
docker images | grep fastapi-lambda-image
```
To run a shell inside the Docker container to inspect its contents, run:
```commandline
docker run -it fastapi-lambda-image:latest /bin/bash
```
## Testing
To run tests, run the following command from the root of the project directory:

View file

@ -14,7 +14,8 @@ RUN apt-get update && apt-get install -y netcat-openbsd
# Install python dependencies
COPY ./backend/requirements/base.txt ./backend/requirements/base.txt
RUN pip install --upgrade pip
RUN pip install -r backend/requirements/base.txt
# Install and clean up temp caches
RUN pip install -r backend/requirements/base.txt && rm -rf /root/.cache
# Copy project files
COPY ./backend/ ./backend

View file

@ -2,7 +2,6 @@ service: fastapi-lambda
provider:
name: aws
runtime: python3.10
region: eu-west-2
architecture: x86_64
environment:
@ -32,46 +31,11 @@ provider:
- arn:aws:s3:::${env:PLAN_TRIGGER_BUCKET}/*
package:
individually: true
patterns:
- 'backend/**'
- '!backend/tests/**'
- 'recommendations/**'
- '!recommendations/tests/**'
# Exclude all of model_data but then re-include the files we need
- '!model_data/**'
- 'model_data/BaseUtility.py'
- 'model_data/config.py'
- 'model_data/optimiser/**'
- 'model_data/__init__.py'
- 'model_data/EpcClean.py'
- 'model_data/utils.py'
- 'model_data/epc_attributes/**'
- 'datatypes/**'
- '!infrastructure/**'
- '!data_collection/**'
- '!node_modules/**'
- '!conservation_areas/**'
- '!open_uprn/**'
- '!land_registry/**'
- '!pytest.ini'
- '**/README.md'
plugins:
- serverless-python-requirements
- serverless-domain-manager
custom:
pythonRequirements:
dockerizePip: true
dockerFile: backend/docker/lambda.Dockerfile
useDocker: true
dockerSsh: true
fileName: backend/requirements/base.txt
dockerBuildCmdExtraArgs:
- '--progress=plain'
customDomain:
domainName: api.${self:provider.environment.DOMAIN_NAME}
createRoute53Record: true
@ -79,7 +43,8 @@ custom:
functions:
app:
handler: backend.app.main.handler
image:
uri: ${env:ECR_URI}:latest
events:
- http:
path: /{proxy+}