This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Auto Scaling Usage Examples

Auto Scaling Usage Examples

This section contains examples of many common usage scenarios for Auto Scaling.

1 - Creating a Basic Auto Scaling Configuration

Auto scaling requires two basic elements to function properly: a launch configuration and an Auto Scaling group. The following examples show how to set up the basic elements of an Auto Scaling configuration.

Create a Launch Configuration

The launch configuration specifies the parameters that Auto Scaling will use when launching new instances for your Auto Scaling group. In this example, we will create a launch configuration with the minimum required parameters - in this case, we set up a launch configuration that specifies that all instances launched in the Auto Scaling group will be of instance type and use the image.To create a launch configuration:

Enter the following command: euscale-create-launch-config MyLaunchConfig --image-id emi-00123456 --instance-type m1.small To verify the launch configuration, enter the following command: euscale-describe-launch-configs MyLaunchConfig You should see output similar to the following:

LAUNCH-CONFIG	MyLaunchConfig	emi-00123456	m1.small

You’ve now created a launch configuration..

Create an Auto Scaling Group

The Auto Scaling group contains settings like the minimum, maximum, and desired number of Eucalyptus instances. At minimum, you must specify the name of the Auto Scaling group, the name of an existing launch configuration, the availability zone, and the minimum and maximum number of instances that should be running. In the following example, we will create an Auto Scaling group called MyScalingGroup in availability zone PARTI00, with a minimum size of 2 and a maximum size of 5.To create an Auto Scaling group: Enter the following command:

euscale-create-auto-scaling-group MyScalingGroup --launch-configuration
                    		MyLaunchConfig --availability-zones PARTI00 --min-size 2 --max-size 5
                    		--desired-capacity 2

Enter the following command to verify the Auto Scaling group you just created:

euscale-describe-auto-scaling-groups MyScalingGroup

This command will return output similar to the following:

AUTO-SCALING-GROUP	MyScalingGroup	MyLaunchConfig	PARTI00		2	5	2	Default
INSTANCE	i-1B853EC3	PARTI00	InService	Healthy	MyLaunchConfig
INSTANCE	i-ABC53ED7	PARTI00	InService	Healthy	MyLaunchConfig

Once you’ve created the Auto Scaling group, Auto Scaling will launch the appropriate number of instances.

2 - Configuring a Demand-Based Scaling Policy

An Auto Scaling group needs a scaling policy to determine when to perform scaling activities. Auto scaling policies work with CloudWatch to identify metrics and set alarms, which are triggered when the metrics fall outside of a specified value range. To configure a scale-based policy, you need to create the policy, and then create CloudWatch alarms to associate with the policy.In the following example, we will create a demand-based scaling policy.

Create Auto Scaling Policies

To create the scaling policies:

Create a scale-out policy using the following command:

euscale-put-scaling-policy MyScaleoutPolicy --auto-scaling-group MyScalingGroup --adjustment=30 --type PercentChangeInCapacity

This command will return a unique Amazon Resource Name (ARN) for the new policy.

arn:aws:autoscaling::706221218191:scalingPolicy:5d02981b-f440-4c8f-98f2-8a620dc2b787:
    autoScalingGroupName/MyScalingGroup:policyName/MyScaleoutPolicy

Create a scale-in policy using the following command:

euscale-put-scaling-policy MyScaleinPolicy -g MyScalingGroup --adjustment=-2  --type ChangeInCapacity

This command will return output containing a unique Amazon Resource Name (ARN) for the new policy, similar to the following:

arn:aws:autoscaling::706221218191:scalingPolicy:d28c6ffc-e9f1-4a48-a79c-8b431794c367:
    autoScalingGroupName/MyScalingGroup:policyName/MyScaleinPolicy

Create CloudWatch Alarms

To create CloudWatch alarms:

Create a Cloudwatch alarm for scaling out when the average CPU usage exceeds 80 percent:

euwatch-put-metric-alarm AddCapacity  --metric-name CPUUtilization --unit Percent
--namespace "AWS/EC2" --statistic Average --period 120 --threshold 80 --comparison-operator 
GreaterThanOrEqualToThreshold --dimensions "AutoScalingGroupName=MyScalingGroup" 
--evaluation-periods 2 --alarm-actions 
arn:aws:autoscaling::706221218191:scalingPolicy:5d02981b-f440-4c8f-98f2-8a620dc2b787:
   autoScalingGroupName/MyScalingGroup:policyName/MyScaleoutPolicy

Create a Cloudwatch alarm for scaling in when the average CPU usage falls below 40 percent:

euwatch-put-metric-alarm RemoveCapacity --metric-name CPUUtilization --unit Percent
--namespace "AWS/EC2" --statistic Average  --period 120  --threshold 40  --comparison-operator 
LessThanOrEqualToThreshold  --dimensions "AutoScalingGroupName=MyScalingGroup" --evaluation-periods 2 
--alarm-actions 
 arn:aws:autoscaling::706221218191:scalingPolicy:d28c6ffc-e9f1-4a48-a79c-8b431794c367:
  autoScalingGroupName/MyScalingGroup:policyName/MyScaleinPolicy

Verify Your Alarms and Policies

Once you’ve created your Auto Scaling policies and CloudWatch alarms, you should verify them.To verify your alarms and policies:

Use the CloudWatch command euwatch-describe-alarms to see a list of the alarms you’ve created:

euwatch-describe-alarms 

This will return output similar to the following:

AddCapacity	INSUFFICIENT_DATA	arn:aws:autoscaling::706221218191:scalingPolicy:5d02981b-f440-4c8f-98f2-8a620dc2b787:
   autoScalingGroupName/MyScalingGroup:policyName/MyScaleoutPolicy	
   AWS/EC2	CPUUtilization	120	Average	2	GreaterThanOrEqualToThreshold	80.0
RemoveCapacity	INSUFFICIENT_DATA	arn:aws:autoscaling::706221218191:scalingPolicy:d28c6ffc-e9f1-4a48-a79c-8b431794c367:
autoScalingGroupName/MyScalingGroup:policyName/MyScaleinPolicy	
   AWS/EC2	CPUUtilization	120	Average	2	LessThanOrEqualToThreshold	40.0

Use the euscale-describe-policies command to see the scaling policies you’ve created:

euscale-describe-policies --auto-scaling-group MyScalingGroup

This will return output similar to the following (note that this output has been split into multiple lines for legibility):

SCALING-POLICY	MyScalingGroup	MyScaleinPolicy	-2	ChangeInCapacity	arn:aws:autoscaling::706221218191:
  scalingPolicy:d28c6ffc-e9f1-4a48-a79c-8b431794c367:
  autoScalingGroupName/MyScalingGroup:policyName/MyScaleinPolicy
SCALING-POLICY	MyScalingGroup	MyScaleoutPolicy	30	PercentChangeInCapacity	arn:aws:autoscaling::706221218191:
  scalingPolicy:5d02981b-f440-4c8f-98f2-8a620dc2b787:
  autoScalingGroupName/MyScalingGroup:policyName/MyScaleoutPolicy

3 - Configuring Health Checks

By default, Auto Scaling group determines the health state of each instance by periodically checking the results of instance status checks. You can specify using the ELB health check method in addition to using the instance health check method.To use load balancing health checks for an Auto Scaling group:

Use the following command to specify ELB health checks for an Auto Scaling group:

euscale-update-auto-scaling-group MyScalingGroup –-health-check-type ELB –-grace-period 300 

4 - Configuring an Instance Termination Policy

You can control how Auto Scaling determines which instances to terminate. You can specify a termination policy when you create an Auto Scaling group, and you can change the termination policy at any time using the command.You can override the default instance termination policy for your Auto Scaling group with one of the following options:

OptionDescription
OldestInstanceThe oldest instance in the Auto Scaling group should be terminated.
NewestInstanceThe newest instance in the Auto Scaling group should be terminated.
OldestLaunchConfigurationThe first instance created using the oldest launch configuration should be terminated.
DefaultUse the default instance termination policy.

To configure an instance termination policy:

Specify the –termination-policies parameter when creating or updating the Auto Scaling group. For example:

euscale-update-auto-scaling-group MyScalingGroup --termination-policies "NewestInstance"

Verify that your Auto Scaling group has updated the termination policy by running the following command: euscale-describe-auto-scaling-groups MyScalingGroup This command should return output similar to the following:

AUTO-SCALING-GROUP	MyScalingGroup	MyLaunchConfig	PARTI00		2	5	2	NewestInstance
INSTANCE	i-1B853EC3	PARTI00	InService	Healthy	MyLaunchConfig
INSTANCE	i-ABC53ED7	PARTI00	InService	Healthy	MyLaunchConfig

5 - Configuring Auto Scaling with Elastic Load Balancing

This example shows how to set up Auto Scaling with Elastic Load Balancing.To set up a load-balanced auto scaling configuration:

If you don’t already have a launch configuration, create one: euscale-create-launch-config MyLaunchConfig --image-id emi-50783D25 --instance-type m1.medium --group mysecuritygroup Create a new auto scaling group associated with a load balancer: euscale-create-auto-scaling-group MyScalingGroup --launch-configuration MyLaunchConfig --load-balancers MyLoadBalancer --availability-zones AcmeAvailabilityZone --min-size 2 --max-size 4 Authorize the security group used by the load balancer for back-end port communication. For example:

$ eulb-describe-lbs --show-long
LOAD_BALANCER	MyLoadBalancer	MyLoadBalancer-408396244283.elb.acme.eucalyptus-systems.com			
{interval=200,target=HTTP:80/,timeout=3,healthy-threshold=2,unhealthy-threshold=4}		AcmeAvailabilityZone		
{protocol=HTTP,lb-port=80,instance-protocol=HTTP,instance-port=80}					
{owner-alias=944786667073,group-name=euca-internal-408396244283-MyLoadBalancer}		
2014-05-28T18:13:17.902Z

euca-authorize mysecuritygroup -u 944786667073 -o euca-internal-408396244283-MyLoadBalancer -p -1 Verify that your Auto Scaling group has been created with a load balancer:

$ euscale-describe-auto-scaling-groups
AUTO-SCALING-GROUP	MyScalingGroup	MyLaunchConfig	AcmeAvailabilityZone	MyLoadBalancer	2	4	2	Default
INSTANCE	i-DFCD0CBC	AcmeAvailabilityZone	InService	Healthy	MyLaunchConfig
INSTANCE	i-B3431043	AcmeAvailabilityZone	InService	Healthy	MyLaunchConfig