This project consists of two services: an API and a worker. The API is built using FastAPI and allows writing log entries to a PostgreSQL database. The worker service integrates with Amazon SQS to offload the endpoint processing to a queue. The project utilizes AWS CDK (Cloud Development Kit) to deploy the necessary infrastructure, including Lambda functions, the database, and SQS.
Alembic is used for database migrations, ensuring a smooth and manageable database schema evolution.
- Requirements
- Setup
- Running the Project
- Testing
- Deployment
- Make Commands
- Project Structure
- Testing the Live API
To run this project, you need the following:
- Python 3.11
- Node.js 20
- Docker
- Virtualenv
- AWS CLI
For Docker, it is recommended to install Orb Stack from here or by running brew install orbstack
.
For the rest of the requirements, it is recommended to use Nix. You can download Nix from here and then run the following command to set up the environment:
nix-shell -p python311 python311Packages.pip nodejs_20 zsh --run zsh
- Clone the repository:
git clone git@github.com:cdragos/fast-log-queue.git
cd fast-log-queue
- Set up the development environment:
make setup_dev
- Start the FastAPI development server:
fastapi dev api/main.py
- Run the project using Docker Compose:
docker compose up
To run the tests, use the following command:
make tests
- Configure AWS CLI:
npm i aws-cli
npm i aws-cdk
aws configure
- For the first-time deployment, run:
make bootstrap
- Deploy the CDK stack:
make deploy
The project includes several Make commands to simplify common tasks:
`make setup_dev`: Set up the development environment.
`make migrations`: Create a new Alembic migration.
`make upgrade`: Upgrade the database to the latest revision.
`make bootstrap`: Bootstrap the CDK stack.
`make deploy`: Deploy the CDK stack.
`make destroy`: Destroy the CDK stack.
`make test`: Run the unit tests.
.
├── api/ # FastAPI API application code
├── worker/ # Worker service code
├── cdk/ # AWS CDK stack definition
├── alembic_migrations/ # Alembic migration scripts
├── shared/ # Shared configuration and models
├── tests/ # Test files for API and worker
To test the live API endpoint, you can use the following curl command:
curl -X POST "https://xw8f3zdndl.execute-api.us-east-1.amazonaws.com/logs" \
-H "Content-Type: application/json" \
-d '{
"message": "This is a test log entry",
"level": "INFO"
}'
To check the logs from the database, you can use the following curl command:
curl https://xw8f3zdndl.execute-api.us-east-1.amazonaws.com/logs