I have completed something I've been wanting to learn for a while: building a web application from scratch and preparing it for cloud deployment. This post documents what I learned and the steps I took to get there.
Starting Point
I knew I wanted to eventually deploy an AI workload to AWS, but I realized I was missing fundamental knowledge about containerization and infrastructure. Rather than jumping straight into the complex stuff, I decided to start with the basics and build up from there.
Building the Application
I chose Python and FastAPI for this project. FastAPI is a modern web framework that's simple enough for beginners but powerful enough for production use. I started by creating a basic "Hello World" application with a few essential endpoints.
The initial app had just two routes: a root endpoint that returned a simple greeting and a health check endpoint. The health check is important because load balancers and container orchestration systems need a way to verify that your application is running properly.
Once I had the basics working, I expanded the application to include more realistic API patterns. I added endpoints that demonstrate path parameters, query parameters, and POST requests with JSON bodies. This helped me understand how modern APIs handle different types of data and requests.
Version Control
Before going any further, I set up Git and pushed my code to GitHub. This was an important step because it meant I had a backup of my work and a foundation for automated deployments later. I created a proper .gitignore file to exclude things like virtual environments and temporary files that shouldn't be in version control.
Containerization with Docker
The next step was containerizing the application. I installed Docker Desktop and learned how to create a Dockerfile. A Dockerfile is basically a recipe that tells Docker how to build your application into a container image.
My Dockerfile started with a Python base image, installed the required dependencies from a requirements.txt file, copied my application code, and specified the command to run when the container starts. The whole process of building and running the container locally took just a few commands.
What impressed me most about containers is how they solve the "it works on my machine" problem. The container includes everything the application needs to run, so it behaves the same way whether it's running on my laptop or in the cloud.
Pushing to a Container Registry
The final step was pushing my Docker image to GitHub Container Registry. This involved creating a personal access token for authentication, tagging my image with the proper format, and uploading it to GitHub's registry.
Now my container image is stored in a central location where it can be pulled from anywhere. This is exactly what I'll need when I deploy to AWS, the registry will be the source for my container images.
What I Learned
The most valuable lesson from today was understanding how all these pieces fit together. A modern application deployment involves several layers: the application code itself, the dependencies it needs, the container that packages everything together, version control to track changes, and a registry to store and distribute container images.
I also learned that taking things one step at a time makes complex topics much more manageable. Instead of trying to learn Docker, Git, FastAPI, and AWS all at once, I focused on getting each piece working before moving to the next.
What's Next
Now that I have a working application containerized and stored in a registry, I'm ready to start using AWS. The next steps will involve leveraging my AWS-SAA skills to deploy my own ECS Fargate for running containers, and using Terraform to define my infrastructure as code.
It's imperative to keep costs low while learning, so I'll be focusing on services like ECS Fargate that offer a good balance between simplicity and cost-effectiveness. I am excited to set up proper monitoring and logging so I can see what's happening with my deployed application.
Final Thoughts
If you're thinking about learning containerization and cloud deployment, my advice is to start small and build incrementally. Don't worry about getting everything perfect on the first try. Focus on understanding what each tool does and why you need it.
The journey from a simple Python script to a containerized application ready for cloud deployment taught me more in one day than weeks of reading tutorials. There's no substitute for actually building something and working through the problems as they come up.
I'm looking forward to the AWS portion of this project and seeing my containerized application running in the cloud. Stay tuned for the next post where I'll document that process.
Oh and here is the link to my project: https://github.com/ka-learns/hello-world-api
No comments:
Post a Comment