11th May

in AWS

Integrating your load balancer with auto scaling groups in EC2 (Amazon AWS)

Posted by Ben Cabot

Amazon’s auto scaling feature is a great tool to ensure that you always meet your desired server capacity. This helps you keep up with the demand from your users while keeping costs down. Amazon’s ELB ties in well with auto scaling groups automatically load balancing servers that have been brought up as the result of an auto scaling action. However some people require more from their load balancer than ELB can provide.

Don’t you wish Amazon ELB could do all this?

  • UDP load balancing
  • Source IP persistence
  • RDP Cookie persistence
  • A static IP or elastic IP entry point
  • Custom health checks
  • Balancing based on actual server load (feedback agent service)
  • Source IP transparency (one arm NAT mode)

This is where the Loadbalancer.org appliance steps in with everything you would expect from a load balancer AND seamless integration with auto scaling groups.

The Loadbalancer.org for AWS appliance will monitor your auto scaling groups, update your configuration based on auto scaling events and add or remove servers from your configuration as required.

First lets create an Auto Scaling group:

To start with you will need to have launched a Loadbalancer.org appliance in EC2 from the AWS Marketplace .Once you have logged in and familiarized yourself with the interface you can then configure your auto scaling group.

Amazon goes through the basic details on creating your first auto scaling group here. In my example I have used the group name “web_as_group” which will launch 2 web servers and keep the group at that size.  This along with a clustered pair of load balancers will give you a highly available site with no downtime should a server fail. Other scaling options are available such as scheduled and dynamic scaling based on events and alarms but we won’t go into that here.

Autoscaling group configuration

Auto scaling group configuration

Next configure a virtual service on the load balancer:

Once you have your auto scaling group you can configure your service to load balance. The appliance supports auto scaling groups when using layer 4 TCP/ UDP,  layer 7 also with SSL termination. Here I am creating a layer 7 TCP service listening on 192.168.1.150 port 80.

layer 7 setup

New layer 7 configuration

And now the cool bit:

After you have added your service you need to modify your new service and this will show you more options. We only need to make a change to one of these options and add our auto scaling group name to the configuration and update.

Layer 7 configuration

Layer 7 auto scaling configuration

Once updated you will be prompted to restart HAProxy and the auto scaling service to complete the configuration. When the services have been restarted the load balancer will start monitoring your auto scaling group and your servers will be shown in the system overview with the server name as the instance id.

system overview ec2 aws

System overview showing auto scaled servers

Now when any changes are made to the servers in the auto scaling group the load balancer will automatically be updated to reflect the changes.  This helps ensure your service is always available to your users leaving you to manage more important tasks.

Awesome! Please let us know what you think….

About the author

Ben Cabot

Ben is our Amazon AWS expert continually working to find new ideas that we can add to our ENTERPRISE AWS product.
When out of the office he is normally found floating around on a kayak or at the lake fishing.

Live chat