Sunday, October 18, 2009

HOW TO SETUP AMAZON LOAD BALANCER AND AUTO SCALING

How to setup Load Balancer for Amazon EC2 instaces/Applications?


First of all we must have Elastic Load Balancer API Tools.

Download Elastic Load Balancer API Tools and unzip into a folder suppose /Backup/elb.


Export variable AWS_ELB_HOME='/Backup/elb'


Elb-create-lb – This is the first command to create Load Balancer.

Go to Directory /Backup/elb/bin and run following command:

./elb-create-lb LBName --ec2-cert-file-path Certificate-file-path --ec2-private-key-file-path privatekey-file-path --availability-zones us-east-1c --listener "protocol=http, lb-port=80, instance-port=80"


This command will give you Load Balancers Public DNS Name.


Next is to register this Load Balancer


./elb-register-instances-with-lb LBName --ec2-cert-file-path Certificate-file-path - -ec2-private-key-file-path privatekey-file-path --instances InstanceID1,InstanceID2


This will show you results like

Instance : InstanceID1
Instance : InstanceID2



Now Setup Auto Scaling


For setting up Auto Scaling using Command Line we must have AutoScaling API Tools.

Download AutoScaling API Tools and unzip into a folder suppose /Backup/amazon/als.

Export variable AWS_AUTO_SCALING_HOME='/Backup/amazon/als'

Go to Directory /Backup/amazon/als/bin

First we need to define / create configuration for AutoScalingGroup

./as-create-launch-config --launch-config ASLaunchConfigurationName - -ec2-cert-file-path /path/to/certificate/file - -ec2-private-key-file-path /path/to/private/key/file - -image-id ami-ID - -instance-type m1.small


OK-Created launch config

Now show installed or created configurations

./as-describe-launch-configs - -ec2-cert-file-path--ec2-cert-file-path /path/to/certificate/file - -ec2-private-key-file-path /path/to/private/key/file


Will display like ::

LAUNCH-CONFIG FirstAS ami-3b53b452 m1.small

Now time to create AutoScalingGroup

./as-create-auto-scaling-group AutoScalingGroupName - -ec2-cert-file-path /path/to/certificate/file - -ec2-private-key-file-path /path/to/private/key/file --launch-configuration ASLaunchConfigurationName --availability-zones us-east-1a - -min-size 2 - -max-size 4 --load-balancers LBName

OK-Created AutoScalingGroup

Now create or setup trigger to customize parameters of AutoScalingGroup for creation and termination of any Instance using following command:

CreateOrUpdateScaling