In every organization High Availability is very important to make continuous and smoothly running their application. In order to dynamically modify resources and distribute traffic according to demand So AWS provide load balancing and auto scaling. In this blog we will explore how to use AWS Elastic Load Balancer and Auto Scaling to create a highly available architecture for your application.
What is Elastic Load Balancing?
Amazon Web Services (AWS) offers a service called Elastic Load Balancing (ELB) that automatically distribute incoming application traffic among several targets such as IP addresses, Amazon EC2 instances, and containers. This is help your application availability and performance by preventing any one resource from being overloaded with traffic.
What is Auto Scaling?
AWS Auto Scaling is a service that automatically adjusts the number of computing resources such as EC2 Instances based on the changing needs of your application. In other words, When traffic increases it is automatically adds more instances according to demand and when traffic decreases it is removes unnecessary ones, So that your application performs well at all times while using the resources it actually needs, it is help to save on costs.
Why High Availability?
High Availability make your applications accessible and performant even if some resources fail. This is achieved through:
- Redundancy : It help to deploy instances in multiple availability zones (AZ).
- Scalability : It is help to automatically add and remove instances based on demand.
- Load Balancing : It is also help to distribute traffic efficiently to healthy instances.
Architecture
- VPC with 2 public subnet and 2 private subnet
- EC2 instance
- AMI
- Load Balancing
- Auto Scaling
Let’s go to demo section
Step 1: Create a VPC and Subnet
- Go to AWS Console → VPC Dashboard
- Click Create VPC
- Name: myvpc
- IPv4 CIDR Block:
10.0.0.0/16(This defines the range of IPs available in the VPC) - Click Create
Step 1.1 : Create a Public and Private Subnet
For high availability, we create:
1. Public Subnet (Subnet-1 in AZ1)
- Go to VPC Dashboard → Subnets → Create Subnet
- Select myvpc
- Name:
Public-Subnet-1 - Availability Zone:
us-east-1a(Choose your region) - CIDR Block:
10.0.1.0/24 - Click Create
2. Public Subnet (Subnet-2 in AZ2)
- Repeat the above steps, but:
- Name:
Public-Subnet-2 - Availability Zone:
us-east-1b - CIDR Block:
10.0.2.0/24
- Name:
3. Private Subnet (Subnet-3 in AZ1)
- Name:
Private-Subnet-1 - Availability Zone:
us-east-1a - CIDR Block:
10.0.3.0/24
4. Private Subnet (Subnet-4 in AZ2)
- Name:
Private-Subnet-2 - Availability Zone:
us-east-1b - CIDR Block:
10.0.4.0/24
Step 2: Create Internet Gateway and Route Table
1. Go to VPC Dashboard → Internet Gateways → Create Internet Gateway
- Name:
MyInternetGateway - Click Create
2. Attach it to the VPC
- Select myvpc
- Click Attach
3. Go to VPC Dashboard → Route Tables → Create Route Table
- Name:
Public-Route-Table - VPC:
myvpc - Click Create
4. Edit Routes → Add Route
- Destination:
0.0.0.0/0 - Target:
Internet Gateway (MyInternetGateway) - Click Save
5. Associate with Public Subnets
- Click Subnet Associations → Edit
- Select Public-Subnet-1 and Public-Subnet-2
- Click Save
Now, Public Subnets have Internet access, but Private Subnets do not.
Step 3: Launch Instances
- Go to EC2 Dashboard → Launch Instance
- Choose Amazon Linux 2 (or Ubuntu)
- Instance Type:
t2.micro(Free Tier eligible) - Network:
myvpc - Subnet: Public-Subnet-1
- Security Group:
- Allow SSH (22) from your IP
- Allow HTTP (80) from the Load Balancer Security Group
- Connect via SSH and install Apache webserver
sudo yum update -y
sudo yum install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd
- For Ubuntu Linux
sudo apt-get update -y
sudo apt-get install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
- Create a Sample Webpage
sudo vi /var/www/html/index.html
ggdG
press i
<h1> Hello we are from High Availability Architecture </h1>
press esc
:wq
Step 4: Create Amazon Machine Image (AMI)
- Select the running EC2 instance.
- Click Actions → Image and Templates → Create Image.
- Name the AMI and wait for it to be available.
Step 5: Setup a load balancer
- Go to EC2 Dashboard → Load Balancers → Create Load Balancer
- Choose Application Load Balancer (ALB)
- Configuration:
- Scheme:
Internet-facing - VPC:
myvpc - Subnets:
Public-Subnet-1 and Public-Subnet-2
- Scheme:
- Create a Target Group:
- Name:
MyTargetGroup - Target Type:
Instance - Protocol:
HTTP - VPC:
myvpc - Health Check Path:
/index.html - Click Create
- Name:
- Register Targets → Select an instance → Click Register
- Click Create Load Balancer
Step 6: Create an Auto Scaling Group (ASG)
- Go to EC2 Dashboard → Auto Scaling Groups → Create Auto Scaling Group
- Configuration:
- Name:
MyAutoScalingGroup - Launch Template: Select the AMI created earlier
- Instance Type:
t2.micro - VPC:
myvpc - Subnets:
Private-Subnet-1 and Private-Subnet-2
- Name:
- Attach Load Balancer:
- Choose MyTargetGroup
- Scaling Policies:
- Min Instances:
2 - Max Instances:
5 - Scaling Policy: Scale out at 50% CPU utilization
- Min Instances:
- Click Create
Step 7: Testing configuration
- Get the Load Balancer DNS Name
- Copy from Load Balancer DNS URL
- Paste it on browser
- You can see Hello we are from High Availability Architecture
- Test Auto Scaling
- Run high CPU load
- Autoscaling launch new instances when CPU crosses 50%
stress --cpu 2 --timeout 300
Hurray ! we are deploy high availability architecture successfully. now you don’t need to worry about your downtime resources or application.
Note: Terminate all the resources to save cost.

