Setting up a auto scaling, load-balanced, webserver with Amazon
Step 1. Define your loadbalancer
As of now, Amazon only supports 2 ports: the default web-traffic on port 80 and ssl secure https traffic on port 443.
Unfortunatly you need to choose 1 of them, but i hope they will change it in the future. You also need to select a availabilityzone, make sure your servers are in the same zone..
elb-create-lb LoadBalancerNameHere –headers –listener “lb-port=80,instance-port=8080,protocol=HTTP” –availability-zones YourPreferedZone
Step 2. Define your LaunchConfiguration
The LaunchConfiguration stores the ami you want to autoscale and the instancetype to go with that
as-create-launch-config LaunchConfigurationNameHer –image-id YourAmiIdHere –instance-type YourInstanceTypeHere
Step 3. Define your AutoScalingGroup
Your AutoScalingGroup combines the data from the previous 2 steps and adds the minimum and maximum amount of instances you want the auto-scaling mechanism to launch
as-create-auto-scaling-group AutoScalingGroupNameHere –launch-configuration LaunchConfigurationNameHere –availability-zones YourPreferedZone –min-size 1 –max-size 5 –load-balancers LoadBalancerNameHere
Step 4. Defining your trigger and launching it all
From the moment you define your trigger, Aws will launch what you have defined.
This example wil launch 1 instance with a trigger to add one instances to maximum of 5 when the 1 minute average CPU load has become higher than 80% for 10 minutes, and will scale down with one instance when the CPU load of the instances has been lower than 40% for 10 minutes
as-create-or-update-trigger –trigger TriggerNameHere –auto-scaling-group AutoScalingGroupNameHere –namespace “AWS/EC2” –measure CPUUtilization –statistic Average –dimensions “AutoScalingGroupName=AutoScalingGroupNameHere” –period 60 –lower-threshold 40 –upper-threshold 80 –lower-breach-increment=-1 –upper-breach-increment 1 –breach-duration 600
Step 5. Monitor and finetune
You can use the folowing to check and monitor if your setup is working