Internal Load Balancing and Auto Scaling in AWS
1. App Tier AMI
- Navigate to Instances in the EC2 dashboard.
- Select the app tier instance you created.
- Under Actions, select Image and Templates → Create Image.
- Provide a name and description, then click Create Image.
- Monitor the image creation progress under AMIs in the left-hand navigation panel.
2. Create a Target Group
- Navigate to Target Groups under Load Balancing in the EC2 dashboard.
- Click Create Target Group.
- Set the target type to Instances.
- Provide a name.
- Set protocol to HTTP and port to 4000 (Node.js app port).
- Select the appropriate VPC.
- Change the health check path to
/health
. - Click Next, skip registering targets, and create the target group.
3. Create an Internal Load Balancer
- Navigate to Load Balancers under Load Balancing in the EC2 dashboard.
- Click Create Load Balancer.
- Select Application Load Balancer and click Create.
- Provide a name and select internal.
- Configure the VPC and private subnets.
- Select the security group created for the internal ALB.
- Set listener to HTTP (port 80).
- Select the previously created target group.
- Click Create Load Balancer.
4. Create a Launch Template
- Navigate to Launch Templates under Instances in the EC2 dashboard.
- Click Create Launch Template.
- Provide a name.
- Select the app tier AMI created earlier.
- Choose Instance Type as t2.micro.
- Skip Key Pair and Network Settings.
- Assign the correct security group for the app tier.
- Under Advanced Details, set the same IAM instance profile as used in other EC2 instances.
- Click Create Launch Template.
5. Configure Auto Scaling
- Navigate to Auto Scaling Groups under Auto Scaling in the EC2 dashboard.
- Click Create Auto Scaling Group.
- Provide a name.
- Select the Launch Template created earlier and click Next.
- Configure VPC and private instance subnets.
- Attach the Auto Scaling Group to the previously created Load Balancer.
- Set desired, minimum, and maximum capacity to 2.
- Click Skip, review settings, and click Create Auto Scaling Group.
6. Update Configuration File
- Open
application-code/nginx.conf
. - Replace
[INTERNAL-LOADBALANCER-DNS]
with your internal load balancer’s DNS. - Upload
nginx.conf
andapplication-code/web-tier
folder to the S3 bucket.
7. Web Instance Deployment
- Navigate to Instances in the EC2 dashboard.
- Click Launch Instances.
- Select Amazon Linux 2 AMI.
- Choose t2.micro instance type.
- Skip the key pair.
- Configure Network, Subnet, and IAM Role (select a private subnet for the web layer).
- Select the web tier security group.
- Choose the correct IAM role for web-tier access.
- Click Launch Instance.
8. Connect to the Instance
- Go to Instances in the EC2 dashboard.
- Select the running instance and click Connect.
- Choose the Session Manager tab and click Connect.
- Test connectivity with:
sudo -su ec2-user
ping 8.8.8.8
9. Configure Web Instance
Install NVM and Node.js
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
source ~/.bashrc
nvm install 16
nvm use 16
Download Web Tier Code from S3
cd ~/
aws s3 cp s3://BUCKET_NAME/web-tier/ web-tier --recursive
Build React App
cd ~/web-tier
npm install
npm run build
10. Install and Configure NGINX
Install NGINX
sudo amazon-linux-extras install nginx1 -y
Replace Nginx Configuration
cd /etc/nginx
sudo rm nginx.conf
sudo aws s3 cp s3://BUCKET_NAME/nginx.conf .
Restart and Configure NGINX
sudo service nginx restart
chmod -R 755 /home/ec2-user
sudo chkconfig nginx on
This guide provides a structured and detailed approach to setting up internal load balancing and auto-scaling in AWS, ensuring a smooth and scalable deployment.