Autoscaling for LAMP on AWS | Setting Up Austoscaling Groups : Part 2
In part 2 of the Autoscaling LAMP in AWS series, let’s discuss how to create autoscaling launch configuration, autoscaling groups and how to verify the setup autoscaling.
Autoscale configuration is now available in console. AWS command lines are no longer needed for implementation.
Complete the following steps as detailed in Part 1 of this series in order to set up autoscaling :
Configure AMI to launch the Instances.
Configure Instance type to launch the instances. (Example: m1.small,m1.large).
Configure KeyPair Name to access the machines.
Configure Security Group to allow the Instances to communicate with other components.
Keep the ELB name readily available.
Keep your availability zones ready. (Example: us-east-1a, us-east-1b).
Set the minimum number of instances for Maximum and Desired Capacity. (Start with zero).
Set Health Check Type. (ELB).
Change Capacity Cooldown time.
Adjust for scale up and scale down.
1. Create the Autoscaling Launch Config
Log in to the AWS console and navigate to Services-> EC2-> Launch Configuration.
Click on “Create Autoscaling Group”.
On the next screen, click on “Create Launch Configuration”.
Create a new launch configuration. The name of the launch configuration must be unique within the scope of the client’s AWS account.
Choose AMI: Go to My AMIs and select the LAMP AMI created.
Choose Instance Type: We’ve selected a micro instance for our example.
Configure Details: Give a name for the Launch Configuration
Add Storage: Keep the values on default.
Configure the Security Group: Select the Security group to launch the autoscaling instances. Review the details and create the Launch Configuration.
In the next window, select “KeyPair” to access the instances.
2. Create the Auto Scaling Group
Create a new Auto Scaling group with a specified name and other attributes. When you make the creation request, the Auto Scaling group is ready for use in other calls.
Navigate to EC2-> Auto Scaling Groups-> Create Autoscaling Group.
Select the existing Launch Configuration (lamp-launch-1) and go to “Next Step”.
Configure Autoscaling Group Details:
Give a name to the Auto Scaling Group.
Group Size: Start with zero instances in order to avoid the immediate creation of instances. The exact number of required instances can be set after these steps are completed, but just set cost optimization values to 0 for now.
Choose 2 availability zones in order to maintain high availability.
In “Advanced Details” choose the values as shown below.
Configure Scaling Policies: Keep minimum and maximum instances count to zero.
Increase Group Size: Keep the name at default.
Execute Policy: Click on “Add new alarm”.
A popup window will appear for creating a “Cloud Watch Alarm”.
For this example, we chose CPU Load average as the autoscaling trigger. Whenever the average CPU load of app servers goes beyond 75% for 5 minutes, autoscaling will trigger the auto-scale-up-policy to launch the 1 instance and attach to load balancer. The application here is CPU intensive and requires more computing power, so we chose the CPU Load Average as the autoscale triggering event.
You can choose any Cloudwatch metric to trigger the autoscaling policy. For example, Disk read/writes, Network In/Out, ELB request count, ELB latency, etc.
Decrease Group size:
Configure Notifications: If you’ve already created notifications, select one to receive the notifications of Autoscaling events, else skip this step for now.
Review the details and click on “Create Autoscaling Group”.
Auto Scaling evaluates the health of each Amazon EC2 instance in the Auto Scaling Group and automatically replaces unhealthy instances in order to keep the Auto Scaling Group size fixed. That ensures that the application is getting the expected compute capacity.
In this example, we’ve chosen to scale down the environment when the average CPU load lowers to 40% for 5 minutes.
After completing the previous steps, it’s time to test autoscaling.
1. Update the Autoscaling group minimum and maximum instances count to 2 and 4. You can change these later to fit your specific requirements.
Navigate to EC2-> Auto Scaling Group- > lamp-asg-1.
Right click on “lamp-asg-1” and select “Edit”.
In the “Details” tab, update Desired Min and Max values to 1, and then save.
Now, navigate to Services->EC2->Instances.
You can see that a new instance has been launched and attached to ELB.
If your health check is configured properly, the instance status will turn into “In Service” rather quickly. Always have a minimum of 2 instances running in order to maintain high availability.
2. How to Update Launch Configuration: It’s not possible to update the existing Launch configuration, so you’ll have to create a new Launch configuration and edit the Autoscaling Group to use that new configuration.
Now, start the application load run and find out the minimum and maximum instances required for your application to handle the load. Then update the AutoScaling Group to meet your needs.
Watch out for Part 3 of this series to understand how to load run an application.
Did you find this useful?
Interested in getting tips, best practices and commentary delivered regularly? Click the button below to sign up for our blog and set your topic and frequency preferences.