Skip to content

zhang-xian0531/weather_app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weather API (Flask + PostgreSQL + Docker + AWS EC2)

A RESTful Weather Data API built with Flask, PostgreSQL, Docker, and deployed on AWS EC2.


Description

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)

Tech Stack

  • Python
  • Flask (RESTful API)
  • PostgreSQL + psycopg2
  • Docker / Docker Compose
  • AWS EC2
  • Linux (SSH)
  • Git / GitHub

System Architecture

Client -> Flask API -> PostgreSQL
           ↓
        Docker
           ↓
        AWS EC2

Project Structure

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

Environment Variables (.env)

This project uses a .env file to manage configuration.

1. Create .env

touch .env

2. Add configuration

cp .env.example .env

Then modify the values if needed.


.env.example

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=5432

Do not upload .env to GitHub.


API Endpoints

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

Run with Docker

docker-compose up -d --build

Then open:

http://localhost:5000

Deployment (AWS EC2)

  1. Launch an EC2 instance (Ubuntu)
  2. Install Docker and Docker Compose
  3. Clone this repository:
git clone https://github.com/zhang-xian0531/weather_app.git
cd weather_app
  1. Create the .env file
  2. Start services:
docker-compose up -d --build
  1. Configure AWS Security Group:
    • Allow inbound traffic on port 5000

Then access:

http://<EC2_PUBLIC_IP>:5000

Features

  • 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

Learning Outcomes

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

Author

About

Weather data REST API with Flask, PostgreSQL, Docker and AWS EC2 deployment

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors