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

Screenshot.png


We do not have any templates so create one

Screenshot.png


Give it a name and scroll down

We put LT1 witch stands for Lunch Template 1

Screenshot.png


Chose AMI and instance type

In our case is Amazon Linux 2 & t2.micro

Screenshot.png


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

Screenshot.png


Select your Security Group and live default Volume settings

Screenshot.png


N0 add tags or network interface at this stage, go to advance details

Screenshot.png


Past User data and CREATE LUNCH TEMPLATE

Screenshot.png


This code run when Instance launch

This code will create an Apache web server and index.html with content.

Screenshot.png


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

Screenshot.png


Crete Auto Scaling Group

On the bottom menu find Auto Scaling Group

We do not have any so create one

Screenshot.png


Give it the name

In our scenario ASG1 and from the drop menu select our Launch template, click next

Screenshot.png


Select VPC

and public subnets

Screenshot.png


Select desired capacity

we chose minimum and maximum running instances, and we do not at this stage chose scaling polices

Screenshot.png


Click next

no notification

Screenshot.png


and next

no tags and create

Screenshot.png


We create Auto scaling group

Screenshot.png


Check EC2 instance

and notices we got two running instances

Screenshot.png


Autoscaling group triger two instance

we got to fresh instance running

Screenshot.png


Autoscaling group activity

Under the activity we see we lunch two instances success

Screenshot.png