
Hey tech enthusiasts! I'm excited to share my journey in building a robust, scalable API for retrieving NFL game schedules using a combination of powerful AWS services. In this project, we'll dive into the practical application of containerization, API management, and serverless computing. This isn't just about theory; it's about building something real, and by the end, you'll have a functioning API.
The Goal: A Scalable and Secure Sports API
Our mission is to create a custom endpoint that can deliver up-to-date NFL game schedules, formatted for easy consumption. This isn't just about fetching data; it's about creating a full-fledged API that is:
- Scalable: Handles increasing traffic without performance bottlenecks.
- Highly Available: Ensures uninterrupted access to the service.
- Secure: Provides access control.
- Organized: Provides clean and readable data to consumers
The Solution: AWS-Powered Architecture
To achieve this, we will implement the following solution:
- Containerization: We will package our Python Flask application into a Docker container.
- ECS on Fargate: Amazon ECS with Fargate will be our container orchestration tool, allowing us to run our containers serverlessly.
- Application Load Balancer (ALB): The ALB will distribute traffic between our container instances ensuring high availability.
- API Gateway: This will expose our API to the outside world with added security and management capabilities.
- SerpAPI: We will use this third-party API as our data source for NFL game schedules.
Architectural Overview

The diagram above illustrates how we will be utilizing the different AWS services.
Technology Stack
- Cloud Provider: AWS
- Containerization: Docker
- Orchestration: Amazon ECS (Fargate)
- Load Balancing: Application Load Balancer (ALB)
- API Management: Amazon API Gateway
- Programming Language: Python
- Data Source: SerpAPI
Code Deep Dive
The project is structured as follows:
sports-api-management/
├── app.py # Flask application for querying sports data
├── Dockerfile # Dockerfile to containerize the Flask app
├── requirements.txt # Python dependencies
├── .gitignore
└── README.md # Project documentation
Here's what each file is responsible for:
- `app.py`: This Python file holds our Flask application. It defines a `/sports` endpoint that when accessed, fetches data from SerpAPI, formats the data and returns a JSON response.
- `Dockerfile`: This file defines the steps to build the container image. This includes using a base Python image, installing dependencies, copying application files, and exposing port 8080.
- `requirements.txt`: Lists the project's Python dependencies, in this case, Flask and Requests.
Hands-On Implementation
Follow these steps to build your sports API:
1. Clone the Repository
git clone https://github.com/ifeanyiro9/containerized-sports-api.git
cd containerized-sports-api
2. Create an ECR Repository
aws ecr create-repository --repository-name sports-api --region us-east-1
3. Build and Push the Docker Image
Make sure you are logged into AWS ECR using the login command provided by the AWS CLI after you created the ECR Repository. You will have to change the account ID in the following command to your AWS Account ID.
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin .dkr.ecr.us-east-1.amazonaws.com
docker build --platform linux/amd64 -t sports-api .
docker tag sports-api:latest .dkr.ecr.us-east-1.amazonaws.com/sports-api:sports-api-latest
docker push .dkr.ecr.us-east-1.amazonaws.com/sports-api:sports-api-latest
Note: Be sure to replace `

4. Set Up ECS Cluster with Fargate
- Go to ECS Console → Clusters → Create Cluster.
- Name your Cluster (e.g., `sports-api-cluster`).
- Choose Fargate as your Infrastructure.
- Create the cluster.

5. Create ECS Task Definition
- Go to Task Definitions → Create New Task Definition.
- Name it (e.g., `sports-api-task`).
- Select Fargate as your Infrastructure.
- Add the container with:
- Name: `sports-api-container`
- Image URI: `
.dkr.ecr.us-east-1.amazonaws.com/sports-api:sports-api-latest` - Port mapping: `8080`
- Environment variables: Key: `SPORTS_API_KEY`, Value: `
`
- Create the task definition.

6. Run the Service with an ALB
- Go to Clusters → Select your cluster → Service → Create.
- Capacity provider: Fargate.
- Select the task definition family you just created.
- Name your service (e.g., `sports-api-service`).
- Set desired task to 2.
- Create a new security group with an open rule for all TCP for demo purposes (not recommended for production).
- Select Application Load Balancer (ALB) for load balancing.
- Create a new ALB (e.g., `sports-api-alb`).
- Set Target Group health check path to `/sports`.
- Create the service.
7. Test the ALB
- After the service deploys note the DNS name of the ALB e.g. `sports-api-alb-
.us-east-1.elb.amazonaws.com` - Confirm the API is accessible by adding `/sports` to the end of the ALB DNS in a browser. e.g. `http://sports-api-alb-
.us-east-1.elb.amazonaws.com/sports`
8. Configure API Gateway
- Go to API Gateway Console → Create API → REST API.
- Name the API (e.g., Sports API Gateway).
- Create resource `/sports` and a GET method.
- Choose HTTP Proxy as integration type and enter the ALB DNS name including `/sports` e.g. `http://sports-api-alb-
.us-east-1.elb.amazonaws.com/sports`. - Deploy to a stage (e.g., `prod`).
- Note the endpoint URL.
9. Test Your API
curl https://.execute-api.us-east-1.amazonaws.com/prod/sports
What We Learned
- Hands-on containerization: How to package an application using Docker.
- Serverless deployment: How to use ECS with Fargate to run applications.
- Load Balancing: How to use an ALB to distribute traffic and ensure high availability.
- API Management: How to expose APIs securely using API Gateway.
Future Enhancements
- Add caching for frequent API requests using Amazon ElastiCache.
- Store user-specific queries with DynamoDB.
- Enhance API security with API keys or IAM-based authentication.
- Implement CI/CD for automated deployments.
Conclusion
This project demonstrates a modern approach to building and managing APIs in the cloud, combining the power of containers, serverless computing, and robust API management. Feel free to use this project as a stepping stone for other complex applications and services. Share your feedback below if you have any questions or insights!