Auto Scaling and Load Balancer with AWS EC2 - rotati/wiki GitHub Wiki

Auto Scaling and Load Balancer with AWS EC2

Auto Scaling is a feature in Amazon EC2 which helps you maintain application availability and allows you to scale your Amazon EC2 capacity up or down automatically according to conditions you define.

This process assumes that:

  1. You've never done any auto scaling before

  2. You got an IAM account and got enough privilege to manage EC2

  3. You got one basic EC2 instance setup and running

  4. You already created a load balancer setup

  5. You already login and is currently on the EC2 Home page

NOTE This process will only show you a very basic concept on how to create EC2 auto scaling. This article is written on 27 April 2016. AWS might change its UI or any or user experience as the time flies.

Step 1: Create AMI

AMI is an image file which is used to be a template to generate new servers

  1. From the left navigation menu under INSTANCES, select Instances

  2. On the right panel, on the instance list, select the instance which you want to be automatically scale

  3. Right click on the instance and choose Image -> Create Image

  4. You should be on the Create Image popup now, fill in Image name, eg(image-01), and leave other field as default, and click Create Image. Another popup should appear with the note of Create Image request received. Click Close.

  5. Wait a few minutes and on the left navigation menu under IMAGES, select AMIs to verify that your current image-01 is there.

Step 2: Create Launch Configurations

  1. On the left navigation menu under AUTO SCALING, select Launch Configurations.

  2. On the right panel click Create Auto Scaling Group

  3. Click Create launch configuration

  4. You should be on the Choose AMI page, on the right tabs, click My AMIs, select your image-01

  5. You should be on the Choose Instance Type, select one of the instance types than suits your needs, then click Next: Configure details

  6. You should be on the Configure details now, fill in config name, eg(config-01), and leave other fields as default, then click Next: Add Storage

  7. You should be on Add Storage page now, leave all everything as default, then click Next: Configure Security Group

  8. You should be Configure Security Group now. From Assign a security group field, choose Select an existing security group, then choose your existing security group you as your EC2 security group. Then click Review button.

  9. You should be on Review page now, click Create launch configuration button. A key pair selection popup should appear. From the first dropdown, select Choose an existing key pair. From the Select a key pair dropdown, select your existing key pair. Click on the acknowledgement check box. Then click Create launch configuration

Step 3: Create Auto Scaling Group

  1. After following all the step above, you should be on the Create Auto Scaling Group page now. Fill in Group name, eg(group-01), select one or more available subnet in the Subnet field, and leave other fields as default. Then click Next: Configure scaling policies

  2. In the Configure scaling policies page, select Use scaling policies to adjust the capacity of this group

  3. Scale policies content with 2 sections, Increase Group Size and Decrease Group Size, should be show. In Increase Group Size section, Add new alarm. A Create Alarm popup should appear. Follow the following config:

    • Deselect Send notification to.
    • Whenever: Average
    • of: CPU Utilization
    • Is: >=
    • 10 Percent
    • Name of alarm: scale-up

Then click Create Alarm. Now you have created an alarm system and applied Increase Group Size policy.

  1. The popup should disappear, and the Execute policy when should be automatically assigned to: scale-up.

Set Taken the action: Add 1 instances when 10 <= CPUUtilization < +infinity.

The above config means Launch a new instance(where instance type is the type you specified in Step 2, point number 5) when CPU usage is equal or higher than 10% for 5 minutes

  1. You have already setup a config to scale up when the CPU usage is facing a specific condition within the period of time. Now let setup the scale down policy.

Under Decrease Group Size section, click Add new alarm. Follow the following config:

* Deselect **Send notification to**.
* Whenever: Average
* of: CPU Utilization
* Is: <
* 5 Percent
* Name of alarm: **scale-down**

Then click Create Alarm. Now you have created an alarm system and applied Decrease Group Size policy.

  1. The popup should disappear, and the Execute policy when should be automatically assigned to: scale-down.

Set Taken the action: Remove 1 instances when 5 >= CPUUtilization > -infinity.

The above config means Remove one instance when CPU usage is less than 5% for 5 minutes

You should be done creating policies for scaling up/down. Click Review

  1. You should be on the Review page, click Create Auto Scaling group. Wait for a several seconds, and your auto scaling group should be done, and the Successfully created Auto Scaling group should appear. Click Done button to visit your current auto scaling group.

Step 4: Choose a load balancer

Under the Details tab of the current auto scaling group, click Edit. In the Load Balancers field, select your existing load balancer.

And that's it! Enjoy scaling!!!