Back
4
☁️ Practical 4: Configure Auto Scaling and Load Balancing
Objective: Set up an Auto Scaling Group and an Application Load Balancer to dynamically spin up responsive web servers.
🖥️ Method 1: Console / GUI Guide (AWS Management Console)
If you prefer to provision infrastructure manually via the Management Console, follow these steps:
- Log In: Go to the EC2 Dashboard.
- Create Template: Click Launch Templates from the sidebar and create a new template using an Amazon Linux AMI, alongside a basic Advanced user data startup script to run a web server.
- Register Targets: Scroll down the sidebar to Target Groups and create a target group designed for HTTP traffic on port 80 based on instances.
- Deploy ALB: Go to Load Balancers and provision an Application Load Balancer (ALB), routing all incoming HTTP listener traffic to your newly created Target Group.
- Create ASG: In the sidebar, select Auto Scaling Groups and create a new group.
- Configure Scaling: Choose your launch template, attach the existing load balancer, and configure a target tracking scaling policy (e.g., dynamically scale up if average CPU utilization exceeds 50%).
🚀 Method 2: Automated Script Guide
For rapid, reproducible deployments, use the provided bash scripts.
🔍 Script Analysis
| Script Name | Action Performed |
|---|---|
4scalingdeploy.sh |
🟢 Sets up a high-availability architecture including an Application Load Balancer (ALB), a Launch Template, Target Groups, and an Auto Scaling Group (ASG) designed to spin up web servers dynamically based on demand. |
4scalingcleanup.sh |
🔴 Removes the Auto Scaling Group smoothly without failure, then deletes the Load Balancer, Launch Template, and Target Groups seamlessly. |
🛠️ Usage Instructions
Prerequisites:
- AWS CLI installed and configured with active credentials.
Execute the following commands from the root directory:
# 1. Navigate to scripts folder
cd scripts/
# 2. Provide execution permission
chmod +x 4_scaling_deploy.sh 4_scaling_cleanup.sh
# 3. Deploy ALB, ASG, and underlying configurations
./4_scaling_deploy.sh
# 4. Delete the scaling group and ALB
./4_scaling_cleanup.sh