Lab Overview
Launch EC2 instances using a Launch Template, place them behind an Application Load Balancer (ALB), and configure Auto Scaling to automatically add or remove instances based on CPU demand. This is the core compute pattern behind nearly every production web application on AWS.
| Service | Purpose | Free Tier |
|---|---|---|
| Amazon EC2 | Virtual servers that run your application | 750 hours/mo t2.micro free (12 months) |
| Auto Scaling Group | Automatically adds/removes EC2 instances based on demand | Free (pay for EC2 instances only) |
| Application Load Balancer | Distributes traffic across multiple EC2 instances | 750 hours/mo free (12 months) |
| Launch Template | Defines the configuration for every new EC2 instance | Free |
| Security Groups | Virtual firewalls controlling inbound/outbound traffic | Always free |
Step-by-Step Instructions
1
Amazon EC2
Create a Security Group
- Search for
EC2and click it - Left sidebar → Security Groups → Create security group
- Name:
WebServer-SG - Description:
Allow HTTP from anywhere - Inbound rules → Add rule: Type: HTTP, Source: Anywhere-IPv4
- Add another rule: Type: SSH, Source: My IP
- Click Create security group
2
Amazon EC2
Create a Launch Template
- Left sidebar → Launch Templates → Create launch template
- Name:
WebServer-Template - AMI: search for Amazon Linux 2023 AMI → select it
- Instance type: t2.micro (Free Tier eligible)
- Key pair: select an existing key pair or create one
- Security groups: select
WebServer-SG - Expand Advanced details → paste the following in User data:
#!/bin/bash yum update -y yum install -y httpd echo "<h1>Hello from $(hostname)</h1>" > /var/www/html/index.html systemctl start httpd systemctl enable httpd
- Click Create launch template
3
Amazon EC2
Create an Application Load Balancer
- Left sidebar → Load Balancers → Create load balancer
- Select Application Load Balancer → Create
- Name:
WebServer-ALB - Scheme: Internet-facing
- Select at least 2 Availability Zones
- Security group: select
WebServer-SG - Listeners: HTTP port 80 (default)
- Create target group: type Instances, name
WebServer-TG, click Next → Create target group - Back in ALB wizard, select
WebServer-TGas the default action - Click Create load balancer
- Wait for state to change to Active — copy the DNS name
4
Amazon EC2
Create an Auto Scaling Group
- Left sidebar → Auto Scaling Groups → Create Auto Scaling group
- Name:
WebServer-ASG - Launch template: select
WebServer-Template→ Next - Select the same Availability Zones you chose for the ALB → Next
- Attach to existing load balancer → select
WebServer-TG→ Next - Desired capacity: 2, Minimum: 1, Maximum: 4
- Scaling policy: Target tracking, Metric: Average CPU utilization, Target: 50%
- Click Next through remaining pages → Create Auto Scaling group
- Watch the EC2 Instances page — 2 instances launch automatically
5
Web Browser
Test Load Balancing
- Paste the ALB DNS name into your browser
- You should see the Hello from hostname page
- Refresh multiple times — the hostname may change as ALB distributes traffic
- Go to EC2 → Instances — confirm 2 instances are running and healthy
TIP: Test Auto Scaling by terminating one instance manually. The ASG will automatically launch a replacement within a few minutes to maintain the desired count.
Verification Checklist
- Security group WebServer-SG created with HTTP (anywhere) and SSH (My IP) inbound rules
- Launch template WebServer-Template created with Amazon Linux 2023 and user data script
- Application Load Balancer WebServer-ALB created and in Active state
- Target group WebServer-TG created and attached to ALB
- Auto Scaling Group WebServer-ASG created with desired=2, min=1, max=4
- CPU target tracking scaling policy configured at 50%
- 2 EC2 instances running and healthy in target group
- ALB DNS name loads the Hello from hostname page in browser
What You Learned
- Amazon EC2 — virtual servers, instance types, AMIs, and user data scripts
- Launch Templates — reusable configuration definitions for EC2 instances
- Application Load Balancer — distributing HTTP traffic across multiple instances
- Target Groups — health-checked collections of EC2 instances behind an ALB
- Auto Scaling Groups — automatic scaling up and down based on demand
- Target tracking policies — scaling based on a metric target like CPU utilization
- Security Groups — stateful virtual firewalls for EC2 instances
Lab Cleanup
IMPORTANT: Delete all resources when finished to stop EC2 charges.
| # | Resource | How to Delete |
|---|---|---|
| 1 | Auto Scaling Group | EC2 → Auto Scaling Groups → WebServer-ASG → Delete |
| 2 | Load Balancer | EC2 → Load Balancers → WebServer-ALB → Delete |
| 3 | Target Group | EC2 → Target Groups → WebServer-TG → Delete |
| 4 | Launch Template | EC2 → Launch Templates → WebServer-Template → Delete |
| 5 | Security Group | EC2 → Security Groups → WebServer-SG → Delete |
| 6 | EC2 Instances | Verify all instances are terminated after ASG deletion |