AWS Cloud Practitioner — Lab 06 of 08

Lab 06 — EC2 & Auto Scaling

Launch EC2 instances behind an Application Load Balancer with Auto Scaling.

Intermediate~$0.01/hr2–4 Hours

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.

ServicePurposeFree Tier
Amazon EC2Virtual servers that run your application750 hours/mo t2.micro free (12 months)
Auto Scaling GroupAutomatically adds/removes EC2 instances based on demandFree (pay for EC2 instances only)
Application Load BalancerDistributes traffic across multiple EC2 instances750 hours/mo free (12 months)
Launch TemplateDefines the configuration for every new EC2 instanceFree
Security GroupsVirtual firewalls controlling inbound/outbound trafficAlways free

Step-by-Step Instructions

1
Amazon EC2
Create a Security Group
  1. Search for EC2 and click it
  2. Left sidebar → Security GroupsCreate security group
  3. Name: WebServer-SG
  4. Description: Allow HTTP from anywhere
  5. Inbound rules → Add rule: Type: HTTP, Source: Anywhere-IPv4
  6. Add another rule: Type: SSH, Source: My IP
  7. Click Create security group
2
Amazon EC2
Create a Launch Template
  1. Left sidebar → Launch TemplatesCreate launch template
  2. Name: WebServer-Template
  3. AMI: search for Amazon Linux 2023 AMI → select it
  4. Instance type: t2.micro (Free Tier eligible)
  5. Key pair: select an existing key pair or create one
  6. Security groups: select WebServer-SG
  7. 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
  1. Click Create launch template
3
Amazon EC2
Create an Application Load Balancer
  1. Left sidebar → Load BalancersCreate load balancer
  2. Select Application Load Balancer → Create
  3. Name: WebServer-ALB
  4. Scheme: Internet-facing
  5. Select at least 2 Availability Zones
  6. Security group: select WebServer-SG
  7. Listeners: HTTP port 80 (default)
  8. Create target group: type Instances, name WebServer-TG, click Next → Create target group
  9. Back in ALB wizard, select WebServer-TG as the default action
  10. Click Create load balancer
  11. Wait for state to change to Active — copy the DNS name
4
Amazon EC2
Create an Auto Scaling Group
  1. Left sidebar → Auto Scaling GroupsCreate Auto Scaling group
  2. Name: WebServer-ASG
  3. Launch template: select WebServer-Template → Next
  4. Select the same Availability Zones you chose for the ALB → Next
  5. Attach to existing load balancer → select WebServer-TG → Next
  6. Desired capacity: 2, Minimum: 1, Maximum: 4
  7. Scaling policy: Target tracking, Metric: Average CPU utilization, Target: 50%
  8. Click Next through remaining pages → Create Auto Scaling group
  9. Watch the EC2 Instances page — 2 instances launch automatically
5
Web Browser
Test Load Balancing
  1. Paste the ALB DNS name into your browser
  2. You should see the Hello from hostname page
  3. Refresh multiple times — the hostname may change as ALB distributes traffic
  4. 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

What You Learned

Lab Cleanup

IMPORTANT: Delete all resources when finished to stop EC2 charges.
#ResourceHow to Delete
1Auto Scaling GroupEC2 → Auto Scaling Groups → WebServer-ASG → Delete
2Load BalancerEC2 → Load Balancers → WebServer-ALB → Delete
3Target GroupEC2 → Target Groups → WebServer-TG → Delete
4Launch TemplateEC2 → Launch Templates → WebServer-Template → Delete
5Security GroupEC2 → Security Groups → WebServer-SG → Delete
6EC2 InstancesVerify all instances are terminated after ASG deletion