Hey Coders! In this blog post, we'll walk through the contents of a repository that demonstrates how to build a weather dashboard application using Docker and AWS S3. This application fetches weather data from the OpenWeather API and saves it to an AWS S3 bucket. Let's dive into the details!
Here's my github repository, feel free to check it: weather-app
If you want to connect follow me on Github: Rene-Mayhrem
Repository Structure
Here's an overview of the repository structure:
weather-dashboard/
├── src/
│ ├── __init__.py
│ └── weather_dashboard.py
├── .env
├── .gitignore
├── Dockerfile
└── README.md
Key Files and Their Purpose
1. init.py
This file serves as the entry point for the application. It imports and calls the main
function from weather_dashboard.py
, ensuring the application runs when the Docker container starts.
from weather_dashboard import main
if __name__ == "__main__":
main()
2. weather_dashboard.py
This is the main application file. It contains the WeatherDashboard
class, which handles fetching weather data from the OpenWeather API and saving it to an AWS S3 bucket. The class also includes methods for creating the S3 bucket if it doesn't exist and saving weather data to the bucket.
3. .env
This file contains environment variables required by the application, such as the OpenWeather API key and AWS credentials. It ensures sensitive information is not hard-coded into the application.
OPENWEATHER_API_KEY=your_openweather_api_key
AWS_BUCKET_NAME=weather-dashboard-${RANDOM}
AWS_ACCESS_KEY_ID=your_aws_access_key_id
AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key
AWS_DEFAULT_REGION=your_aws_default_region
4. .gitignore
This file specifies which files and directories should be ignored by Git. It includes entries for the
.env
file, Python cache directories, and other unnecessary files.
.env
__pycache__/
*.zip
test/
data/
5. Dockerfile
The Dockerfile defines the steps to build a Docker image for the application. It installs the necessary dependencies, copies the application code, and sets the command to run the application.
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Install AWS CLI
RUN apt-get update && apt-get install -y awscli
COPY .env .
COPY src/ ./src
CMD ["python", "src/__init__.py"]
6. README.md
The README file provides detailed instructions on how to set up and run the application. It includes sections on prerequisites, setup steps, usage, AWS configuration, and resources for further reading.
Setting Up the Application
To set up the application, follow these steps:
-
Clone the repository:
git clone https://github.com/Rene-Mayhrem/aws-weather-app.git cd weather-dashboard
Create a .env file with your OpenWeather API key and AWS credentials.
-
Build the Docker image:
docker build -t weather-dashboard .
-
Run the Docker container:
docker run --name aws-app weather-dashboard
Conclusion
This repository provides a comprehensive example of how to build a weather dashboard application using Docker and AWS S3. By following the setup instructions, you can easily fetch weather data and save it to an S3 bucket. The repository structure and detailed documentation make it easy to understand and extend the application for your own needs.
Feel free to comment and discuss.
Top comments (0)