Random thoughts of a warped mind…

September 24, 2012

Get an Amazon load balancer running in <5 mins

Filed under: All,Amazon EC2,AWS ELB,EC2,Ruby — Srinivas @ 15:47

Heres a quick Ruby script to get an Amazon HTTP load balancer running in ~5 minutes (or lesser). The code in this github project assumes you have an AWS account backed up by a credit card and have your AWS Access Key ID and Secrets available – Paste them into the YML config file from the git repo.

Modify the region, node counts, AMI ID etc in the config YML to suit your requirements – Keep in mind that the user-data script assumes you are on a Ubuntu/Debianish distro and sets up a test CGI page on the instances based on that assumption.

The script will try to span as many availability zones in the AWS region as possible, that is – If you run the script with a nodecount of 10 in US-EAST-1 region, then it will round robin to create nodes in us-east1a,b,c,d,e and then again us-east-1a-1e i.e. you will end up with 10 nodes in all, with 2 each per AZ…

You can always modify the user-data script to push in a more custom CGI script and use a custom AMI to test more fancy stuff (e.g. if you want to test something that has a database backend etc…).

Here is the link to the Git repo – ELB-in-15

Run elbsetup.rb with command “create” to create the instances, set them up from the user-data script and then spawn an Elastic Load Balancer that uses these instances as backends. Similarly use action “destroy” with the ELB Name to unregister the instances from the ELB, drop the ELB and finally drop the backend EC2 instances as well…

Powered by WordPress