Skip to main content

Lab: Auto Scaling Configuration

Lab Objective​

Design and configure a complete Auto Scaling solution for a web application with variable traffic patterns.

Part 1: Scenario​

Context​

NewsPortal is a news site that experiences unpredictable traffic spikes during breaking news. The technical team wants to automate scaling to:

  • Maintain performance during spikes
  • Reduce costs during off-peak hours

Traffic Data​

┌─────────────────────────────────────────────────────────────┐
│ NEWS PORTAL TRAFFIC PATTERNS │
├─────────────────────────────────────────────────────────────┤
│ │
│ NORMAL DAY │
│ ─────────────── │
│ │
│ Visitors ▲ │
│ │ ┌────┐ │
│ 50,000 ─┤ ┌┘ └┐ │
│ │ ┌┘ └┐ ┌──┐ │
│ 30,000 ─┤ ┌──┘ └──────┘ └┐ │
│ │ ┌──┘ └──┐ │
│ 10,000 ─┤──┘ └── │
│ │ │
│ └─────┬─────┬─────┬─────┬─────┬─────► Hour │
│ 6h 9h 12h 18h 21h │
│ │
│ BREAKING NEWS (unpredictable) │
│ ─────────────────────────── │
│ │
│ Visitors ▲ │
│ │ ▲ Sudden spike x10 │
│ 200,000 ─┤ ╱╲ │
│ │ ╱ ╲ │
│ 100,000 ─┤ ╱ ╲ │
│ │ ╱ ╲ │
│ 20,000 ─┤──────╱ ╲────────── │
│ │ │
│ └─────────────────────────────────► Time │
│ │
└─────────────────────────────────────────────────────────────┘

Requirements​

AspectRequirement
Availability99.9%
Response time< 500ms (P95)
Min capacity5,000 visitors/min
Max capacity200,000 visitors/min
BudgetOptimize costs outside peaks

Part 2: Design Exercises​

Exercise 2.1: Sizing​

Knowing that a t3.medium instance can handle 500 requests/second, calculate:

QuestionYour Answer
Minimum instances (normal)?
Instances for x10 spike?
Recommended min for HA?
Recommended max?
💡 Solution
Normal traffic: 50,000 visitors/min = 833 req/sec
Instances needed: 833 / 500 = 2 instances

x10 spike traffic: 200,000 visitors/min = 3,333 req/sec
Instances needed: 3,333 / 500 = 7 instances (rounded)

Recommended min: 2 (HA Multi-AZ)
Recommended max: 10 (safety margin)

Desired initial: 2

Exercise 2.2: Policy Choice​

Which scaling policy(ies) do you recommend and why?

PolicyAppropriate?Justification
Target Tracking CPU??
Target Tracking Requests??
Scheduled??
Step Scaling??
💡 Solution
PolicyAppropriate?Justification
Target Tracking CPU⚠️ PartialUseful but CPU not always correlated to requests
Target Tracking Requests✅ YESDirectly related to user traffic
Scheduled⚠️ PartialPredictable day/night patterns, but not breaking news
Step Scaling✅ YESQuick response to sudden spikes

Recommendation: Combine Target Tracking (requests) + Scheduled (base)

Exercise 2.3: Launch Template Configuration​

Complete the Launch Template configuration:

# Launch Template Configuration
LaunchTemplateName: newsportal-lt

# To complete:
AMI: _______________
InstanceType: _______________
SecurityGroupIds:
- _______________
KeyName: _______________
UserData: |
#!/bin/bash
_______________
_______________
_______________
💡 Solution
LaunchTemplateName: newsportal-lt

AMI: ami-0123456789 (Amazon Linux 2, preconfigured)
InstanceType: t3.medium
SecurityGroupIds:
- sg-web-servers
KeyName: newsportal-key
UserData: |
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
# Or app deployment via CodeDeploy
aws s3 cp s3://newsportal-deploy/latest.tar.gz /tmp/
tar -xzf /tmp/latest.tar.gz -C /var/www/html/

Exercise 2.4: ASG Configuration​

Complete the Auto Scaling Group configuration:

AutoScalingGroupName: newsportal-asg

# Capacity
MinSize: ___
MaxSize: ___
DesiredCapacity: ___

# Network (2 AZ minimum)
VPCZoneIdentifier:
- _______________
- _______________

# Health Checks
HealthCheckType: _______________
HealthCheckGracePeriod: ___

# Target Group
TargetGroupARNs:
- _______________
💡 Solution
AutoScalingGroupName: newsportal-asg

MinSize: 2
MaxSize: 10
DesiredCapacity: 2

VPCZoneIdentifier:
- subnet-private-az-a
- subnet-private-az-b

HealthCheckType: ELB # Uses ALB health checks
HealthCheckGracePeriod: 300 # 5 minutes for app startup

TargetGroupARNs:
- arn:aws:elasticloadbalancing:...:targetgroup/newsportal-tg/xxx

Part 3: Policy Configuration​

Exercise 3.1: Target Tracking​

Create a Target Tracking policy to maintain 1000 requests per target:

# Complete the command
aws autoscaling put-scaling-policy \
--auto-scaling-group-name newsportal-asg \
--policy-name _______________ \
--policy-type _______________ \
--target-tracking-configuration '{
"TargetValue": ___,
"PredefinedMetricSpecification": {
"PredefinedMetricType": "_______________",
"ResourceLabel": "app/newsportal-alb/xxx/targetgroup/newsportal-tg/yyy"
},
"ScaleOutCooldown": ___,
"ScaleInCooldown": ___
}'
💡 Solution
aws autoscaling put-scaling-policy \
--auto-scaling-group-name newsportal-asg \
--policy-name request-target-tracking \
--policy-type TargetTrackingScaling \
--target-tracking-configuration '{
"TargetValue": 1000.0,
"PredefinedMetricSpecification": {
"PredefinedMetricType": "ALBRequestCountPerTarget",
"ResourceLabel": "app/newsportal-alb/xxx/targetgroup/newsportal-tg/yyy"
},
"ScaleOutCooldown": 60,
"ScaleInCooldown": 300
}'

Exercise 3.2: Scheduled Scaling​

Configure scheduled scaling for day/night patterns:

# Morning scale up (8h UTC, Mon-Fri)
aws autoscaling put-scheduled-update-group-action \
--auto-scaling-group-name newsportal-asg \
--scheduled-action-name _______________ \
--recurrence "_______________ " \
--min-size ___ \
--max-size ___

# Evening scale down (22h UTC, every day)
aws autoscaling put-scheduled-update-group-action \
--auto-scaling-group-name newsportal-asg \
--scheduled-action-name _______________ \
--recurrence "_______________" \
--min-size ___ \
--max-size ___
💡 Solution
# Morning scale up (8h UTC, Mon-Fri)
aws autoscaling put-scheduled-update-group-action \
--auto-scaling-group-name newsportal-asg \
--scheduled-action-name morning-scale-up \
--recurrence "0 8 * * MON-FRI" \
--min-size 3 \
--max-size 10

# Evening scale down (22h UTC, every day)
aws autoscaling put-scheduled-update-group-action \
--auto-scaling-group-name newsportal-asg \
--scheduled-action-name evening-scale-down \
--recurrence "0 22 * * *" \
--min-size 2 \
--max-size 5

Part 4: Monitoring and Alerts​

Exercise 4.1: CloudWatch Dashboard​

List the essential metrics to monitor:

MetricNamespaceAlert Threshold
?AWS/EC2?
?AWS/ApplicationELB?
?AWS/AutoScaling?
?Custom?
💡 Solution
MetricNamespaceAlert Threshold
CPUUtilizationAWS/EC2> 80%
TargetResponseTimeAWS/ApplicationELB> 500ms
RequestCountAWS/ApplicationELBinfo only
HealthyHostCountAWS/ApplicationELB< 2
GroupDesiredCapacityAWS/AutoScalinginfo only
GroupInServiceInstancesAWS/AutoScaling< min
HTTPCode_Target_5XX_CountAWS/ApplicationELB> 10/min

Exercise 4.2: Scaling Alert​

Create an SNS alert to notify during scaling events:

# 1. Create the SNS topic
aws sns create-topic --name _______________

# 2. Subscribe via email
aws sns subscribe \
--topic-arn arn:aws:sns:...:_______________ \
--protocol email \
--notification-endpoint _______________

# 3. Configure ASG notifications
aws autoscaling put-notification-configuration \
--auto-scaling-group-name newsportal-asg \
--topic-arn arn:aws:sns:...:_______________ \
--notification-types \
"autoscaling:EC2_INSTANCE_LAUNCH" \
"autoscaling:EC2_INSTANCE_TERMINATE" \
"_______________"
💡 Solution
# 1. Create the SNS topic
aws sns create-topic --name newsportal-scaling-alerts

# 2. Subscribe via email
aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789:newsportal-scaling-alerts \
--protocol email \
--notification-endpoint ops@newsportal.com

# 3. Configure ASG notifications
aws autoscaling put-notification-configuration \
--auto-scaling-group-name newsportal-asg \
--topic-arn arn:aws:sns:us-east-1:123456789:newsportal-scaling-alerts \
--notification-types \
"autoscaling:EC2_INSTANCE_LAUNCH" \
"autoscaling:EC2_INSTANCE_TERMINATE" \
"autoscaling:EC2_INSTANCE_LAUNCH_ERROR"

Part 5: Validation Tests​

Test Plan​

TestMethodExpected Result
Scale OutGenerate loadNew instances in < 5 min
Scale InStop loadReduction after cooldown
FailoverTerminate instanceAuto replacement
Health CheckStop appInstance marked unhealthy

Load Test Script​

#!/bin/bash
# test-load.sh - Simulate a traffic spike

ALB_DNS="newsportal-alb-xxx.region.elb.amazonaws.com"
DURATION=300 # 5 minutes
CONCURRENCY=100

echo "Starting load test..."
echo "URL: http://$ALB_DNS"
echo "Duration: $DURATION seconds"
echo "Concurrency: $CONCURRENCY"

# Use Apache Bench or hey
hey -z ${DURATION}s -c $CONCURRENCY http://$ALB_DNS/

echo "Test completed. Check CloudWatch and ASG."

Validation Checklist​

┌─────────────────────────────────────────────────────────────┐
│ VALIDATION CHECKLIST │
├─────────────────────────────────────────────────────────────┤
│ │
│ ☐ Scale out works (new instances) │
│ ☐ Scale in works (terminated instances) │
│ ☐ ALB health checks detect failures │
│ ☐ Unhealthy instances automatically replaced │
│ ☐ SNS notifications received │
│ ☐ Metrics visible in CloudWatch │
│ ☐ Scheduled actions respected │
│ ☐ Response time maintained < 500ms under load │
│ │
└─────────────────────────────────────────────────────────────┘

Final Deliverable​

Document to Produce​

  1. Auto Scaling Architecture (diagram)
  2. Complete Configuration (Launch Template + ASG)
  3. Scaling Policies (Target Tracking + Scheduled)
  4. Monitoring Plan (metrics + alerts)
  5. Test Results (CloudWatch screenshots)

Evaluation Criteria​

CriterionPoints
Correct sizing/15
Complete ASG configuration/25
Policies suited to scenario/20
Monitoring and alerts/15
Documented tests/15
Document quality/10
Total/100

Next week: MODULE 10 - Route 53