Subscribe to Our Weekly Newsletter
Setting Up an Auto-Scaled and Load-Balanced Amazon EC2 Application
Setting Up an Auto-Scaled and Load-Balanced Amazon EC2 Application
The following steps will instruct you on how to set up an auto-scaled, load-balanced Amazon EC2 Application:
1) Firstly, you will need to open a command prompt window on your computer.
(In Microsoft Windows, this can be done by starting the command prompt application (You can start it from the Start menu by clicking on Programs, then clicking on Accessories, and finally clicking on Command Prompt)).
2) Now, you will need to use the Auto Scaling “as-create-launch-config” command.
For this particular example, we will be using a publicly available Windows AMI, running Microsoft Windows Server 2008 and Microsoft Internet Information Services (IIS).We will use a “t1.micro” instance type, and use the security group and key pair that we have already created in the previous steps. In this particular example, the key pair file is located in the same directory in which we are creating our Auto Scaling group. Also, we will not be specifying a region, as we are using the default region, US East (Virginia).
Note: The AMI being used in this particular example is a part of the AWS Free Usage Tier. Those eligible for the free tier will not be charged for launching the Amazon EC2 instance. However, if you are ineligible for the AWS Free Usage Tier, the charges incurred in this example are still minimal. For further information regarding Amazon EC2 pricing, please refer to the Amazon Elastic Compute Cloud (Amazon EC2) details page.
PROMPT> as-create-launch-config MyLC -image-id ami-498d5520 -instance-typet1.micro -group webappsecuritygroup -key mykeypair |
Auto Scaling will return the following:
OK-Created launch config |
Note: For ease, you can copy/paste the commands from the document into the command line window. To successfully copy/paste the contents in the command line window, use the right-click button on your mouse. If you still have trouble in getting the commands to work, please ensure that the command was pasted correctly.
3) You will now be using the Auto Scaling “as-create-auto-scaling-group” command.
In this particular example, we will be using two Availability Zones. This is a very good way of building fault-tolerant applications, for if one Availability Zone experiences an outage, traffic will automatically be routed to another Availability Zone. Also, the number of instances being launched in the Auto-Scaling group will be automatically, and evenly, distributed across the Availability Zones.
PROMPT>as-create-auto-scaling-group MyAutoScalingGroup -launch-configuration MyLC -availability-zones us-east-1b, us-east-1c -min-size 1 -max-size 1 -load-balancers MyLB |
Auto Scaling will return an output which is similar to the following example output:
OK-Created AutoScalingGroup |
4) Now, we will use the Auto Scaling “as-put-scaling-policy” command, and create a policy that will enlarge your fleet of instances.
PROMPT>as-put-scaling-policy MyScaleUpPolicy -auto-scaling-group MyAutoScal ingGroup -adjustment=1 -type ChangeInCapacity -cooldown 300 |
Auto Scaling will again return an output similar to the following example output:
POLICY-ARN arn:aws:autoscaling:us-east-1:012345678901:scalingPolicy:cbe7da4e-5d00-4882-900a 2f8113431e30:autoScalingGroupName/MyAutoScalingGroup:policyName/MyScaleUpPolicy |
Note: In this particular example, we are only creating a scale-out policy to save time. However, you should create a scale-in policy as well. Auto-Scaling helps in decreasing the number of instances when an application doesn’t need the resources, thus saving you money. To successfully create a scale-in policy, change the policy name, and also change the adjustment from 1 to -1.
5) Finally, we will verify the existence of your Auto Scaling group, by using the “as-describe-auto-scaling-groups” command.
PROMPT>as-describe-auto-scaling-groups MyAutoScalingGroup -headers |
Auto-Scaling will return the following:
AUTO-SCALING-GROUP GROUP-NAME LAUNCH-CONFIG AVAILABILITY-ZONES MIN-SIZE MAX-SIZE DESIRED-CAPACITY AUTO-SCALING-GROUP MyAutoScalingGroup MyLC us-east-1b,us-east- 1c 1 1 1 INSTANCE INSTANCE-ID AVAILABILITY-ZONE STATE STATUS LAUNCH-CONFIG INSTANCE i-xxxxxxxx us-east-1c InService Healthy MyLC |
Congratulations! You have just launched an auto-scaled and load-balanced Amazon EC2 application. For further information on Auto-Scaling, please refer to the Auto-Scaling Documentation. Costs will be incurred by you as long as your Amazon EC2 instances are running. To terminate these instances, please refer to the How to Terminate EC2 Instances section.