A RESTful Weather Data API built with Flask, PostgreSQL, Docker, and deployed on AWS EC2.
This project is a backend RESTful API system for managing weather data.
It fetches real-time weather data from an external API and stores it in a PostgreSQL database.
The system supports historical queries and conditional search functionality.
This project demonstrates a complete backend workflow including:
- API development (Flask)
- Database design (PostgreSQL)
- Containerized deployment (Docker)
- Cloud deployment (AWS EC2)
- Python
- Flask (RESTful API)
- PostgreSQL + psycopg2
- Docker / Docker Compose
- AWS EC2
- Linux (SSH)
- Git / GitHub
Client -> Flask API -> PostgreSQL
↓
Docker
↓
AWS EC2
weather_app/
├── app.py # Entry point
├── api.py # External weather API handling
├── db.py # Database operations
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
├── .env.example
└── .gitignore
This project uses a .env file to manage configuration.
touch .envcp .env.example .envThen modify the values if needed.
It is recommended to provide an example file:
DB_HOST=db
DB_NAME=your_db_name
DB_USER=your_user_name
DB_PASSWORD=your_password
DB_PORT=5432Do not upload
.envto GitHub.
| Method | Endpoint | Description |
|---|---|---|
| GET | /weather |
Get current weather data and save it to database |
| GET | /history |
Get recent weather history |
| GET | /history/search?date=YYYY-MM-DD |
Search weather history by date |
docker-compose up -d --buildThen open:
http://localhost:5000
- Launch an EC2 instance (Ubuntu)
- Install Docker and Docker Compose
- Clone this repository:
git clone https://github.com/zhang-xian0531/weather_app.git
cd weather_app- Create the
.envfile - Start services:
docker-compose up -d --build- Configure AWS Security Group:
- Allow inbound traffic on port
5000
- Allow inbound traffic on port
Then access:
http://<EC2_PUBLIC_IP>:5000
- RESTful API design
- PostgreSQL database integration
- Modular architecture (API / DB separation)
- Docker containerization
- AWS EC2 cloud deployment
- Historical data query and filtering
- Environment-based configuration with
.env
Through this project, I gained hands-on experience in:
- Backend API development with Flask
- Database design and integration with PostgreSQL
- Containerization with Docker and Docker Compose
- Linux server operation and SSH
- Cloud deployment using AWS EC2
- Environment variable management with
.env - Version control with Git and GitHub