Project Description
This project demonstrates building a containerized api management system for querying sports data. It uses Amazon ECS for running containers, Amazon API Gateway for exposing REST Endpoints and an external Sports API for real-time sports data. The project showcases advanced cloud computing practices, including API management, container orchestration, and secure AWS integrations.
Project Architecture
Project Setup
- Clone the Repository
git clone https://github.com/ifeanyiro9/containerized-sports-api.git
cd containerized-sports-api
-Create an ECR Repository
aws ecr create-repository --repository-name sports-api --region us-east-1
- Authenticate, Build, and Push Docker Image
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com
docker build --platform linux/amd64 -t sports-api .
docker tag sports-api:latest <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/sports-api:sports-api-latest
docker push <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/sports-api:sports-api-latest
-
Set Up an ECS Cluster with Fargate
- Create an ECS Cluster:
- Navigate to the ECS Console → Clusters → Create Cluster.
- Name the cluster (e.g., sports-api-cluster).
- Choose Fargate as the infrastructure type, then create the cluster.
Create a Task Definition:
-
Go to Task Definitions → Create New Task Definition.
- Name the task definition (e.g., sports-api-task).
- Choose Fargate as the infrastructure type.
- Add the container:
- Name: sports-api-container
- Image URI: .dkr.ecr.us-east-1.amazonaws.com/sports-api:sports-api-latest
- Container Port: 8080
- Environment Variables:
- Key: SPORTS_API_KEY
- Value:
- Save and create the task definition.
-
Deploy the Service with an Application Load Balancer (ALB):
- Go to Clusters → Select Cluster → Service → Create Service.
- Configuration:
- Capacity Provider: Fargate
- Task Definition: sports-api-task
- Service Name: sports-api-service
- Desired Tasks: 2
- Networking:
- Create a new security group allowing TCP traffic.
- Type: All TCP, Source: Anywhere
- Load Balancer:
- Select Application Load Balancer (ALB).
- ALB Configuration:
- Create a new ALB named sports-api-alb.
- Health Check Path: /sports
- Create the service.
-
Test the ALB:
- Retrieve the ALB DNS name (e.g., sports-api-alb-.us-east-1.elb.amazonaws.com).
- Verify the API is accessible by visiting http://sports-api-alb-.us-east-1.amazonaws.com/sports.
-
Configure API Gateway
- Create a REST API:
- Navigate to API Gateway Console → Create API → REST API.
- Name the API (e.g., Sports API Gateway).
- Set Up Integration:
- Create a resource /sports.
- Create a GET method and choose HTTP Proxy as the integration type.
- Enter the ALB DNS name followed by /sports.
- Deploy the API: -Deploy the API to a stage (e.g., prod) and note the endpoint URL.
-
Test the System
- Use a browser or curl to test:
curl https://<api-gateway-id>.execute-api.us-east-1.amazonaws.com/prod/sports
- Use a browser or curl to test:
Conclusion
This project demonstrates how to build a scalable, containerized sports data API management system using modern AWS services such as ECS with Fargate, API Gateway, and CloudWatch. By integrating these services, we achieved a reliable and secure infrastructure for hosting and managing APIs, while also adhering to best practices like containerization and least privilege IAM policies. Future enhancements like caching with ElastiCache, user-specific data storage with DynamoDB, and implementing CI/CD pipelines can further optimize the system for performance and maintainability. This documentation serves as a comprehensive guide to replicate, deploy, and extend the system, empowering developers to leverage AWS for similar use cases.
Top comments (0)