- Launch Template vs Launch Configuration
- Auto Scaling Group basics (min / desired / max capacity)
- Integrating an ALB and Target Group
- Target-tracking scaling policy (average CPU)
- Testing instance replacement and dynamic scale-out

web-autoscale). The ASG requires either a Launch Template (recommended) or a Launch Configuration. Launch Templates provide versioning, parameter overrides, and more flexibility.
Use a Launch Template when you want version control and the ability to override settings at the ASG level (for example, instance type or user data). If you need the simplest option and don’t plan to reuse or version the configuration, a Launch Configuration can still work.

- Provide a name (e.g.,
myweb-template) and description (e.g.,prod web server). - Choose the AMI to use. If you have a custom AMI (for example, a Linux AMI with nginx preinstalled), pick it from “My AMIs / Owned by me”.
- Select the instance type (for free-tier eligibility, choose
t2.micro).

- Use an existing security group that allows inbound HTTP (port 80).
- Leave subnet selection undefined in the template so the ASG can target private subnets at creation time.
- Leave storage, tags, and advanced options at their defaults unless you have specific requirements.

- No load balancer
- Attach an existing load balancer
- Create a new load balancer (recommended for web servers)
- Make it internet-facing
- Place the ALB in public subnets
- Configure an HTTP listener on port 80
- Create a Target Group that the ALB will forward requests to (for example,
web-autoscale-1-TG)


For scaling, add a target-tracking scaling policy. In this demo we set the policy to maintain average CPU utilization at
40%. This relatively low threshold demonstrates autoscaling quickly; in production choose thresholds that match your workload (often higher than 40%). The ASG will add or remove instances to keep the average CPU near the target.
When ready, review and create the Auto Scaling Group. AWS will provision:
- the Auto Scaling Group,
- the initial EC2 instance(s),
- the ALB,
- the Target Group.

initial and move to healthy once health checks pass.

- Simulate instance failure:
- Terminate the instance that the ASG created. The Auto Scaling Group will detect the drop below
Desired capacityand will launch a replacement instance automatically.
- Terminate the instance that the ASG created. The Auto Scaling Group will detect the drop below

-
Monitor ASG activity:
- Open the ASG Activity history to see entries showing instance termination and the subsequent launch of a replacement to restore desired capacity.
-
Simulate high load to trigger scale-out:
- Increase CPU load on the running instance to make the ASG’s target-tracking policy scale out additional instances. The configured policy aims for average CPU =
40%; when the average rises above that, the ASG will add instances up to the configured maximum (3in this demo).
- Increase CPU load on the running instance to make the ASG’s target-tracking policy scale out additional instances. The configured policy aims for average CPU =
- SSH to the instance (example):
- Check current CPU usage with
top:
top output showing idle CPU before stress:
- Run a CPU stress process (example using the
stressutility):
stress, top will show CPU near 100% for the stress process:
Desired capacity) to bring average CPU closer to the 40% target. The ASG may add instances up to the configured maximum (3 in this demo).


- Delete the Auto Scaling Group (this will terminate managed instances).
- Remove the ALB and Target Group if they are no longer required.
- Remove any other resources you created (security groups, key pairs, custom AMIs) to avoid ongoing charges.
Best practices: choose appropriate scaling thresholds and use cooldown or warm-up periods that fit your application startup characteristics. Test scaling policies in a controlled environment and always clean up resources to avoid unexpected costs.
- AWS Auto Scaling: https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html
- Application Load Balancer (ALB): https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html
- Launch Templates: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html
- Target Tracking Scaling Policies: https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scaling-target-tracking.html