Auto Scaling

Reference scripts. No Explanations; almost self explanatory if you understand bash and little bit of aws

If you ever come across this article. Just ignore it. I warn you just ignore it unless you want a migrane on both side of your head.

more UserData.txt 

yum update -y --security
yum install -y
yum-config-manager --enable epel
yum -y install httpd php stress
chkconfig httpd on
service httpd start
cd /var/www/html

echo 'UserData has been successfully executed. ' >> /home/ec2-user/result
#erase any history or security information that might have accidentally been left on the instance when the image was taken.
find -wholename /root/.*history -wholename /home/*/.*history -exec rm -f {} \;
find / -name 'authorized_keys' -exec rm -f {} \;
rm -rf /var/lib/cloud/data/scripts/*
aws ec2 run-instances --key-name vockey --instance-type t2.micro --image-id ami-0464d49b8794eba32 --user-data file:///home/ec2-user/UserData.txt --security-group-ids sg-0f2ae4e44bd99bec9 --subnet-id subnet-080b9434fdcb5b074 --associate-public-ip-address --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=WebServerBaseImage}]' --output text --query 'Instances[*].InstanceId'
#wait untill the ec2 is in running state
aws ec2 wait instance-running --instance-ids <NEW-INSTANCE-ID>
aws ec2 describe-instances --instance-id <NEW-INSTANCE-ID> --query 'Reservations[0].Instances[0].NetworkInterfaces[0].Association.PublicDnsName'
#create a custom ami
aws ec2 create-image --name WebServer --instance-id <NEW-INSTANCE-ID>

load balancer .target group

launch template

asg .attach to existing load balancer