By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
(For AWS Solutions Architect – Associate & Real-World Deployments)
You’re a cloud engineer at a startup. Your app runs on EC2 instances, and traffic spikes unpredictably—sometimes 10x during a marketing campaign, then back to normal. If you over-provision, you waste money. If you under-provision, users see "503 Service Unavailable." Auto Scaling Groups (ASGs) and Launch Templates are your solution.
Why this matters in production:- Cost savings: Scale down when idle (e.g., dev environments at night).- High availability: Replace failed instances automatically.- Resilience: Survive AZ outages by distributing instances across multiple zones.- Operational sanity: No more manual instance launches or "oops, we forgot to patch this server."
Real-world scenario:You inherit a monolithic app running on 10 t3.large instances. Traffic doubles overnight, and your boss asks: - "Why are we paying for 10 instances when we only need 3 at 3 AM?" - "Why did the site crash when one instance failed?" - "How do we roll out security patches without downtime?"
t3.large
This guide solves all three.
/health
t3.xlarge
aws --version
Launch templates replace the older "Launch Configurations." They’re versioned and support more features (e.g., T2/T3 unlimited, Elastic Graphics).
# Create a launch template with user data to install Apache aws ec2 create-launch-template \ --launch-template-name web-app-template \ --launch-template-data '{ "ImageId": "ami-0c55b159cbfafe1f0", # Amazon Linux 2 (us-east-1) "InstanceType": "t3.micro", "KeyName": "your-key-pair", "SecurityGroupIds": ["sg-12345678"], # Replace with your SG ID "UserData": "IyEvYmluL2Jhc2gKeXVtIGluc3RhbGwgaHR0ZCAteQpzeXN0ZW1jdGwgc3RhcnQgaHR0ZApzeXN0ZW1jdGwgZW5hYmxlIGh0dGQKZWNobyAiSGVsbG8gV29ybGQhIiA+IC92YXIvd3d3L2h0bWwvaW5kZXguaHRtbA==", "TagSpecifications": [{ "ResourceType": "instance", "Tags": [{ "Key": "Name", "Value": "web-app" }] }] }'
Verify:
aws ec2 describe-launch-templates --launch-template-names web-app-template
Attach the launch template to an ASG with scaling policies.
# Create ASG across 2 AZs with min 2, max 4 instances aws autoscaling create-auto-scaling-group \ --auto-scaling-group-name web-app-asg \ --launch-template LaunchTemplateName=web-app-template,Version='$Latest' \ --min-size 2 \ --max-size 4 \ --desired-capacity 2 \ --vpc-zone-identifier "subnet-12345678,subnet-87654321" # Replace with your private subnets \ --target-group-arns "arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/web-app-tg/1234567890" # Replace with your ALB target group ARN \ --health-check-type ELB \ --health-check-grace-period 300
aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names web-app-asg
Add a target tracking policy to scale based on CPU.
aws autoscaling put-scaling-policy \ --auto-scaling-group-name web-app-asg \ --policy-name cpu-target-tracking \ --policy-type TargetTrackingScaling \ --target-tracking-configuration '{ "PredefinedMetricSpecification": { "PredefinedMetricType": "ASGAverageCPUUtilization" }, "TargetValue": 50.0, "DisableScaleIn": false }'
aws autoscaling describe-policies --auto-scaling-group-name web-app-asg
Simulate load to trigger scaling.
# Install stress tool on one instance (SSH into it first) sudo yum install -y stress stress --cpu 4 --timeout 600
Check scaling activity:
aws autoscaling describe-scaling-activities --auto-scaling-group-name web-app-asg
Expected output:
"Description": "Launching a new EC2 instance: i-1234567890abcdef0", "StatusCode": "InProgress"
# Delete ASG (instances will terminate) aws autoscaling delete-auto-scaling-group --auto-scaling-group-name web-app-asg --force-delete # Delete launch template aws ec2 delete-launch-template --launch-template-name web-app-template
bash --mixed-instances-policy '{ "LaunchTemplate": { "LaunchTemplateSpecification": { "LaunchTemplateName": "web-app-template" }, "Overrides": [ { "InstanceType": "t3.micro" }, { "InstanceType": "t3.small" } ] }, "InstancesDistribution": { "OnDemandPercentageAboveBaseCapacity": 20, "SpotAllocationStrategy": "capacity-optimized" } }'
Name
Environment
Owner
Version='$Latest'
Version='2'
UpdatePolicy
yaml UpdatePolicy: AutoScalingRollingUpdate: MinInstancesInService: 1 MaxBatchSize: 1
CPUUtilization
UnHealthyHostCount
GroupDesiredCapacity
RequestsPerSecond
OldestInstance
NewestInstance
Answer: Increase the cooldown period or use step scaling instead of target tracking.
Scenario: "You need to update your ASG with a new AMI without downtime."
Answer: Create a new launch template version, then update the ASG with a rolling update policy.
Trap Distinction:
Launch Template vs. Launch Configuration:
Scenario: "Your app is stateful. How do you gracefully terminate instances?"
Challenge:Create an ASG that scales between 1 and 3 instances based on a custom CloudWatch metric (RequestCountPerTarget). Use a launch template with a t3.micro instance and a user data script that installs Nginx.
RequestCountPerTarget
t3.micro
Solution:
# 1. Create launch template aws ec2 create-launch-template \ --launch-template-name nginx-template \ --launch-template-data '{ "ImageId": "ami-0c55b159cbfafe1f0", "InstanceType": "t3.micro", "UserData": "IyEvYmluL2Jhc2gKeXVtIGluc3RhbGwgLXkgbmdpbngKc3lzdGVtY3RsIHN0YXJ0IG5naW54CnN5c3RlbWN0bCBlbmFibGUgbmdpbng=", "TagSpecifications": [{ "ResourceType": "instance", "Tags": [{ "Key": "Name", "Value": "nginx" }] }] }' # 2. Create ASG aws autoscaling create-auto-scaling-group \ --auto-scaling-group-name nginx-asg \ --launch-template LaunchTemplateName=nginx-template,Version='$Latest' \ --min-size 1 \ --max-size 3 \ --desired-capacity 1 \ --vpc-zone-identifier "subnet-12345678,subnet-87654321" # 3. Create scaling policy aws autoscaling put-scaling-policy \ --auto-scaling-group-name nginx-asg \ --policy-name request-scaling \ --policy-type TargetTrackingScaling \ --target-tracking-configuration '{ "CustomizedMetricSpecification": { "MetricName": "RequestCountPerTarget", "Namespace": "AWS/ApplicationELB", "Statistic": "Sum", "Unit": "Count" }, "TargetValue": 1000.0 }'
Why it works:- The ASG scales based on RequestCountPerTarget (a metric published by ALB).- Nginx is installed via user data, so new instances are ready immediately.
aws autoscaling create-auto-scaling-group
--health-check-type ELB
aws autoscaling put-scaling-policy
--policy-type TargetTrackingScaling
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.