Backend Building
How to run the backend locally:¶
The API for rezoning contains two parts: the Rezoning API and the Export Function. Each needs to be run individually. But before running any of the two, localstack needs to be running.
Clone repo & checkout to the development branch:¶
First, you need to fetch the source code for the backend using the following command:
Move into the directory using:
Using the current development branch (the main branch contains the production code)
Running localstack:¶
- Make sure you have localstack setup by following instructions from LocalStack CLI offical install instruction
Start LocalStack in the background:¶
Start local stack using:
Note: One common problem might happen with permissions, here is an article on how to fix it: Solving docker permissions
-
Install aws cli tool:¶
- Install AWS CLI tools by following instructions from Installing or updating the latest version of the AWS CLI
- Check if aws cli was installed correctly using
aws --version
: this will display the version of the installed aws-cli toolchain.
-
Set up AWS configuration:
It will ask for AWS Access Key, AWS Secret Key and Region, for example us-east-2. -
Create the SQS queue in localstack:
- Create the export bucket used to communicate the exporting requests between the API and the export function:
Running Rezoning API:¶
In order to work with Rezoning locally, you need AWS access to the processed data (Currently around 330Gb of data) and a certain Airtable.
- You can do this by setting the following environment variables: Replace <%> with the keys but omit <%>
export AIRTABLE_KEY=<%AIRTABLE_KEY> AWS_ACCESS_KEY_ID=<%AWS_ACCESS_KEY_ID> AWS_SECRET_ACCESS_KEY=<%AWS_SECRET_ACCESS_KEY>
- Optional: If your network is slow, you need to download data using the following command that will make sure every file in the AWS data bucket will be copied over locally to the rezoning-data directory in your home directory:
- Optional: To work with the local data, the following environment variables need to be set:
- Install the dependencies using:
- Install Uvicorn using:
- Start the server using:
Run export function locally:¶
Note:: Make sure to replace <% %> placeholders with your AWS information before running the code below.