Building a Weather Dashboard: Fetch and Store Real-Time Weather Data with Python, OpenWeather API, and AWS S3

Building a Weather Dashboard: Fetch and Store Real-Time Weather Data with Python, OpenWeather API, and AWS S3

A weather dashboard that fetches real-time weather data for multiple cities using the OpenWeather API and stores the data in AWS S3.


Building projects that integrate APIs and cloud services offers invaluable hands-on experience with real-world applications. In this article, I’ll guide you through my Weather Dashboard project—a Python-based application designed to fetch real-time weather data for multiple cities using the OpenWeather API and securely store it in AWS S3 for seamless data management.

You can find the complete project on GitHub: Weather Dashboard

Purpose

Gain hands-on experience and join the #DevOpsAllStarsChallenge, an initiative hosted by Cloud Engineers and DevOps professionals dedicated to helping others get involved in the field. It's a vibrant and supportive community, and I highly recommend exploring the Discord channel if you're interested in learning more!


🌟 Project Overview

The Weather Dashboard is a Python-based CLI tool designed to:

  • Fetch real-time weather data for predefined cities.

  • Display temperature, humidity, and weather conditions in the terminal.

  • Save weather data as JSON files to an AWS S3 bucket for storage and analysis.


Prerequisites

  • Python 3.x installed on your system.

  • An AWS account with an IAM user account with IAMFullAccess privileges.

  • An OpenWeather API account and your API key.

  • AWS CLI installed

The project highlights the use of:

  • Python for scripting.

  • Boto3 for interacting with AWS S3.

  • OpenWeather API for fetching weather data.


🚀 Features

  1. Fetches real-time weather data for cities like Srinagar, Delhi, and Mumbai.

  2. Displays weather details, including temperature, humidity, and conditions.

  3. Stores the fetched data in an S3 bucket for later use.

  4. Handles errors gracefully, such as API key issues or connectivity problems.


Create an API key in OpenWeather

Create an account with OpenWeather, select "API Keys" and generate an API key. This will be used later in the .env file within the Git repo.

Create an IAM user in AWS, assign a group, permissions and generate an Access Key

For further explanation, please reference the AWS IAM user documentation.

I have created the user "weather-dashboard-user", and added the policy of "AmazonS3FullAccess" and “AmazonIAMFullAcces”. This gives the user the necessary permissions to create an S3 bucket.


Weather Dashboard Setup and Launch

Clone the Repository

git clone https://github.com/DarFaizan18/weather-dashboard.git
cd weather-dashboard

Install Dependencies Use pip to install the required Python packages:

pip install -r src/requirements.txt

Configure Environment Variables Create a .env file in the src/ directory and add the following:

OPENWEATHER_API_KEY=your_openweather_api_key
AWS_BUCKET_NAME=your_s3_bucket_name

💻 Usage

Once set up, run the script to fetch weather data:

python src/weather_dashboard.py

Here’s what the program does:

  1. Checks if the S3 bucket exists: Creates one if it doesn't.

  2. Fetches weather data: Pulls data for cities like Srinagar, Delhi, and Mumbai using the OpenWeather API.

  3. Displays data: Outputs temperature, humidity, and weather descriptions in the terminal.

  4. Saves to AWS S3: Uploads JSON files with weather data to your S3 bucket.

Example Output

Terminal output:

💡
Now delete the S3 bucket to ensure you don't get billed

🛠️ Technologies Used

  • Python: Core language for scripting.

  • Boto3: AWS SDK for Python to interact with S3.

  • OpenWeather API: Source of real-time weather data.

  • AWS S3: Cloud storage for saving weather data.

  • AWS CLI: Used to connect with the AWS account

  • Dotenv: To manage environment variables securely.


Conclusion

This article showcased a foundational example of building a weather dashboard using Python, AWS S3, and the OpenWeather API.

I hope this article serves as a valuable starting point for your weather dashboard project.


Did you find this article valuable?

Support Faizan Mehraj by becoming a sponsor. Any amount is appreciated!