Scalable Web Application Deployment : From GitHub to AWS ECR , ECS with Load Balancing and Auto-Scaling

Scalable Web Application Deployment : From GitHub to AWS ECR , ECS with Load Balancing and Auto-Scaling

ยท

3 min read

In this project we will deloy a scalable flask app on AWS ECS (Fargate) with the help of AWS ECR which is a container image registry.

Flow of the Project

We will clone a repo from github -> Build a docker image for the app -> Create AWS ECR after configuring aws cli -> Push image to AWS ECR -> Create an ECS Cluster ---> Create a task definition to create Container -> Create a service in cluster with Loadbalancing and autoscaling -> Access our app through browser.

Tools and Technology Used:

Git , Docker , Aws-cli , EC2 , AWS ECR , AWS ECS , LoadBalancer , AutoScaling.

PHASE 1 : Git and Docker

Task 1) Create an EC2 instance and install docker on it.

sudo apt update && sudo apt upgrade -y

sudo apt install docker.io -y
sudo usermod -aG docker $USER
sudo chmod 666 /var/run/docker.sock
docker --version

Task 2) Clone the repo.

git clone <repo-link>

Task 3 ) Build the docker image.

docker build -t sample-flask-app .

Task 4) To push the image to ECR we need to install and configure aws-cli. To install and configure use below commands

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt install unzip
unzip awscliv2.zip
sudo ./aws/install
aws --version

#create access key and secret key to configure aws-cli
aws configure

Phase 2 : Create ECR Repository

Task 5) Now we will move to AWS .

  • Create an AWS ECR repository so that we can push our docker image into it.

  • Click on view push commands to see the commands which you need to run from your terminal to push docker image to ECR.

  • Run all commands to push your image.

Phase 3: Create ECS Cluster and Task Definition

Task 6) Create an ECS cluster to deploy our app (may take 5-10 mins).

Task 7) After cluster we will create a Task Definition.

  • Task Definition is like a template which tell ECS clusters which and how a container should be configured and run.

  • Make sure you mention the port on which container is running.

Phase 4: Creating service for our Tasks

Task 8) Our task definition is created so now we have to create a service in Cluster to run that task , we will attach a LoadBalancer to it to handle the load and that will also help us to access the application.

  • Create a LoadBalancer for our service-

  • Creating Auto-Scaling for our service so that based on high traffic our service can increase the number of tasks.

Phase 5: Accessing our Application through LB

Task 8 ) Accessing our App.

  • Our tasks are running

  • LoadBalancer is created.

  • We can access our App with the help of DNS name of our LoadBalancer.

Output


Thanks all. Good luck out there!

Follow for more such amazing content :)

Happy Learning ๐Ÿ˜Š


ย