This project demonstrates how to build a containerized system for a simple Flask application that fetches NFL sports data.
- Docker
- AWS ECS (Elastic Container Service)
- AWS ECR (Elastic Container Registry)
- Elastic Load Balancer (ALB)
- SerpAPI
- Python (Flask)
Before starting, ensure you have the following:
- AWS User with Required Permissions
- Allocate permissions for ECS, API Gateway, and ECR.
- AWS CLI
- Install and configure the AWS CLI with your user details.
- SerpAPI Account
- Register on SerpAPI and acquire an API Key.
- Docker
- Install and configure Docker on your local environment.
Clone the project repository to your local environment:
git clone https://github.com/ViolaSangut/Containerization-and-Load_balancing-with-AWS.git
Create an Elastic Container Registry (ECR) repository in AWS to store your Docker images:
aws ecr create-repository --repository-name sports-api --region us-east-1
Authenticate Docker with your ECR repository:
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
Build the Docker image, tag it, and push it to the ECR repository:
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
Navigate to the AWS ECS Console and create a new cluster. Select Fargate as the launch type.
Define a task in ECS with the following:
- Container image URI from ECR.
- Port configuration.
- Environment variables (e.g., API keys).
Deploy your task as a service within the ECS cluster:
- Configure the desired number of tasks.
- Set up networking (security groups, subnets).
- Attach an Application Load Balancer (ALB) for traffic routing.
Retrieve the DNS name of the ALB from the AWS Console and test it by accessing the application in a browser.
Example:
http://sports-api-alb-<AWS_ACCOUNT_ID>.us-east-1.elb.amazonaws.com
Expose your ECS service as a REST API using API Gateway:
- Create a new API.
- Configure resources and methods (e.g., GET for fetching data).
- Integrate the API Gateway with your ALB DNS.
Test the API Gateway endpoint by accessing it in a browser or using curl:
curl https://<api-gateway-id>.execute-api.us-east-1.amazonaws.com/prod/sports
- Setting up a scalable, containerized application with ECS.
- Creating public APIs using API Gateway.
- Add caching for frequent API requests using Amazon ElastiCache.
- Integrate DynamoDB to store user-specific queries and preferences.
- Secure the API Gateway using API Keys or IAM-based authentication.
- Implement CI/CD pipelines for automating container deployments.