Loading ...

Would you like to discuss your environment with a knowledgable engineer?

Preferred communication *

Thank you. We will be in touch with you shortly

Autoscaling ELB to multiple aiScaler instances



Here I will explain how you can use aiScaler as a Load Balancer in Amazon Web Service with auto scaling, to launch your application servers and register them with aiScaler when scaling up and deregister them when scaling down. Specifically I will explain the followings:

  • what aiScaler instance to launch so it can be used as a Load Balancer;
  • how to create an Amazon Machine Image for your application server and tune it so it can register and deregister with aiScaler server;
  • how tocreate a Launch Configuration for the Auto Scaling Group;
  • how tocreate an Auto Scaling Group that will use aiScaler instance and Launch Configuration from above;
  • how tocreate an Auto Scaling Policy for scaling up, which will add a new instance to the Auto Scaling Group;
  • how tocreate an Auto Scaling Policy for scaling down, which will remove an instance from the Auto Scaling Group;
  • how tocreate CloudWatch Alarms that will use the Auto Scaling Policies for scaling up or down and when specific conditions are met.

Once done, you will have a working auto scaling group that will work like in the little diagram below:
aiScaler -> one or more application instances
Then I will describe how you can remove all the configuration in case you want to delete it.

Launching an aiScaler instance

To use aiScaler as a Load Balancer with auto scaling you should use the Market Place AMI of aiScaler. For this go to Amazon EC2 Console and click on Launch Instance. In the appeared window select AWS Markeplcate and search for aiScaler in “Search AWS Marketplace” field. Then just follow the instructions to launch the instance like any other Amazon Instance, as it’s described here.
One note though, if you want to use aiScaler as a load balancer, I would suggest to use at least the Large instance to handle more traffic.

Create an AMI for application server

You will have to create an AMI that will contain all the software needed for your application and deployment scripts that will configure the application on boot. This is different for every application and I can not provide much support here, we can provide support for this separately, so if you like just drop an email to support@aiscaler.com and we will be happy to help.
The part that you need to add here, are two small scripts that will register with aiScaler on boot, and deregister with aiScaler on stop/terminate.
You can download and use the following simple scripts for the register and deregister purpose, aicache_connect.sh and aicache_disconnect.sh scripts are attached at the bottom of this page.
You need to have the key pair file to connect to your aiScaler instance copied into your application AMI and the path to this file should be set in the scripts as KEY_FILE variable.
Below are the variables from the script explained:

  • KEY_FILE=”/root/test.pem” – this is the key file which is used to connect to aiScaler server and register;
  • AICACHE_CONFIG=”/etc/aicache/aicache.cfg” – this is the configuration file of aiScaler which is currently in use;
  • UPDATE_SCRIPT=”/usr/local/aicache/aicache_config_server.py” – this is the location of aiScaler update script on the aiScaler server, this shouldn’t change;
  • LISTENER=”all” – this sets the website configuration section to update in the aiScaler configuration, “all” means that all sections will be updated;
  • APP_TYPE=”http” – the type of application, can be http or https;
  • APP-PORT=80 – the port on which application listens to requests on the application server.

You also have to provide the IP address of aiScaler instance as user-data, so application servers know to which server they should register, this will be covered in the creating launch configuration section.
The last step here is to add aicache_connect.sh to run at boot and aicache_disconnect.sh to run at stop/terminate. For this you can do the followings on ubuntu machine:

cp aicache_connect.sh aicache_disconnect.sh /etc/init.d/
update-rc.d aicache_connect.sh defaults
update-rc.d aicache_disconnect.sh defaults
rm /etc/rc0.d/K20aicache_connect.sh /etc/rc1.d/K20aicache_connect.sh /etc/rc6.d/K20aicache_connect.sh
rm /etc/rc2.d/S20aicache_disconnect.sh /etc/rc3.d/S20aicache_disconnect.sh /etc/rc4.d/S20aicache_disconnect.sh /etc/rc5.d/S20aicache_disconnect.sh

The above will ensure that register is done on boot, and deregister is done on stop/terminate.
I strongly recommend testing that registration is working fine before going into production.

Create Elastic Load Balancer

Select “Load Balancers” under “Network & Security” in the EC2 Management Console, and start the Create Load Balancer wizard.

Name your Load Balancer, and adjust the health checks for your web application, e.g. “/” instead of the default “/index.html”.

Do not add any instances to your load balancer, this will be done by the Autoscaling Group.

Create Launch Configuration and Auto Scaling Group

Using the AWS Console we’ll:

  • Create a Launch Configuration for your Auto Scaling Group
  • Create an Auto Scaling Group
  • Create two alarms to trigger scaling of our group

To start configuring Auto Scaling navigate to the EC2 Dashboard and select Launch Configurations under Auto Scaling.

Create Auto Scaling Launch Configuration

Start the Auto Scaling Launch Configuration Wizard.

In Step 1 select My AMIs and locate the AMI you created at the previous step.

In Step 2 select your desired instance type, e.g. m1.large.

In Step 3 name your Launch Configuration, e.g. “AiScaler Launch Configuration”. Select Advanced Options, and in the User Data field input the private IP address of the aiScaler server. It is needed on the application servers so they know where to connect and register.

You can now skip to Review and Create Launch Configuration. The wizard will bring you directly to the Create Auto Scaling Group wizard.

Create Auto Scaling Group


In Step 1 name your group,e.g. “AiScaler Auto Scaling Group”, and select your Availability Zones, we recommend selecting them all.

Under Advanced Options, check “Recieve traffic from Elastic Load Balancer(s)”. Select the name of the ELB you created in the step before in the pull down menu.

In Step 2 we configure scaling policies. Select “Use scaling policies to adjust the capacity of this group”.

Next to Execute Policy when select Create alarm.

Unselect “Send notification to”.

Set the alarm to “Whenever CPU Utilization is >= 80 Percent”.

Next to Take Action select Add 1 instance.

Repeat for decrease policy size, selecting “Whenever CPU Utilization is <= 20 Percent”.

Skip to Review and Create Auto Scaling group.

US (208) 948-9786‬   EU ‭+31 621302365