Maintaining High Availability with Auto Scaling (for Linux)

519

// Info
ElasticLoadBalancer, qls-95965-ElasticL-EIJLTRMF6WHF
AMIId, ami-f0091d91
KeyName, qwikLABS-L251-959650
AvailabilityZone, us-west-2a
SecurityGroup, qls-959650-9e4e0af87f9270ec-Ec2SecurityGroup-1FLS2W4COXMWO

// Bootstrap

#!/bin/sh
yum -y install httpd php mysql php-mysql
chkconfig httpd on
/etc/init.d/httpd start
cd /tmp
wget http://us-east-1-aws-training.s3.amazonaws.com/self-paced-lab-4/examplefiles-as.zip
unzip examplefiles-as.zip
mv examplefiles-as/* /var/www/html
// CLI
aws configure
aws autoscaling create-launch-configuration –image-id ami-f0091d91 –instance-type t2.micro –key-name qwikLABS-L251-959650 –security-groups qls-959650-9e4e0af87f9270ec-Ec2SecurityGroup-1FLS2W4COXMWO –user-data file:///home/ec2-user/as-bootstrap.sh –launch-configuration-name lab-lc
aws autoscaling create-auto-scaling-group –auto-scaling-group-name lab-as-group –availability-zones us-west-2a –launch-configuration-name lab-lc –load-balancer-names qls-95965-ElasticL-EIJLTRMF6WHF –max-size 5 –min-size 1
aws autoscaling create-or-update-tags –tags “ResourceId=lab-as-group, ResourceType=auto-scaling-group, Key=Name, Value=AS-Web-Server, PropagateAtLaunch=true”
// Auto Scaling with load balance

// SNS
aws autoscaling describe-auto-scaling-notification-types
aws autoscaling put-notification-configuration –auto-scaling-group-name lab-as-group –topic-arn arn:aws:sns:us-west-2:124944012613:lab-as-topic –notification-types autoscaling:EC2_INSTANCE_LAUNCH autoscaling:EC2_INSTANCE_TERMINATE

// Auto scaling policy

// Scale up:
aws autoscaling put-scaling-policy –policy-name lab-scale-up-policy –auto-scaling-group-name lab-as-group –scaling-adjustment 1 –adjustment-type ChangeInCapacity –cooldown 300
//Scale down policy
aws autoscaling put-scaling-policy –policy-name lab-scale-down-policy –auto-scaling-group-name lab-as-group –scaling-adjustment -1 –adjustment-type ChangeInCapacity –cooldown 300

// Cloudwatch CPU Alert

// View scaling activity
aws autoscaling describe-scaling-activities –auto-scaling-group-name lab-as-group