This project implements a 3-tier architecture using AWS, Terraform, and a Python backend.
A classic 3-tier architecture deployed on AWS using Terraform.
- Frontend: Static HTML site served by Nginx
- Backend: Flask REST API written in Python, running on Gunicorn, using PyMongo for database access and Redis for caching
- Data Layer:
- Amazon DocumentDB (MongoDB-compatible) as the primary datastore
- Amazon ElastiCache (Redis) for in-memory caching
.
├── diagram
└── src
└── app
│ ├── backend
│ └── frontend
└── aws
└── modules
├── backend
├── documentdb
├── elasticache
├── frontend
├── iam
└── network
-
Configure AWS Credentials: Make sure you have your AWS credentials configured properly.
-
Initialize Terraform:
cd aws terraform init -
Apply Terraform:
terraform apply
-
Destroy Infrastructure:
terraform destroy
- Request: Client ➔ Backend
- Check: Backend ➔ Redis (Search for data)
- Decision:
- IF HIT: Redis ➔ Backend ➔ Client ✅
- IF MISS: Redis ➔ Backend (Not found) ➔ Step 4
- Fetch: Backend ➔ MongoDB (Get original data)
- Update: MongoDB ➔ Backend ➔ Redis (Save for next time)
- Deliver: Backend ➔ Client 🏁
The backend provides the following API endpoints:
GET /system-status: Returns the status of the system.GET /get_data/<string:key>: Retrieves data from the cache or database.GET /list_all_data: Retrieves all data from the database.POST /set_data: Inserts new data into the database.DELETE /delete_data/<string:key>: Deletes data from the database.GET /health: Returns the health of the backend and its database connections.
- AWS Architecture Center
- Terraform Documentation
- Flask Documentation
- DocumentDB Documentation
- ElastiCache Documentation
This project is for educational purposes and is based on a common architectural pattern. For more examples and best practices, please refer to the AWS Architecture Center.
