We will create lunche template and auto-scaling group
Where there is no red arrow or description, leave the default values
Under the instances select Lunch Template
We do not have any templates so create one
Give it a name and scroll down
We put LT1 witch stands for Lunch Template 1
Chose AMI and instance type
In our case is Amazon Linux 2 & t2.micro
Select your Key pair your VPC and security group
You have to have you key pair created or click create new key pair. Select VPC and Security group
Select your Security Group and live default Volume settings
N0 add tags or network interface at this stage, go to advance details
Past User data and CREATE LUNCH TEMPLATE
This code run when Instance launch
This code will create an Apache web server and index.html with content.
Copy User data
This code will work with Amazon linux
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
INTERFACE=$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/)
SUBNETID=$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/${INTERFACE}/subnet-id)
echo '<center><h1>This instance is in the subnet wih ID: SUBNETID </h1></center>' > /var/www/html/index.txt
sed "s/SUBNETID/$SUBNETID/" /var/www/html/index.txt > /var/www/html/index.html
Past code and Create Lunch Template
and all done you create very own launch template
Crete Auto Scaling Group
On the bottom menu find Auto Scaling Group
We do not have any so create one
Give it the name
In our scenario ASG1 and from the drop menu select our Launch template, click next
Select VPC
and public subnets
Select desired capacity
we chose minimum and maximum running instances, and we do not at this stage chose scaling polices
Click next
no notification
and next
no tags and create
We create Auto scaling group
Check EC2 instance
and notices we got two running instances
Autoscaling group triger two instance
we got to fresh instance running
Autoscaling group activity
Under the activity we see we lunch two instances success