forked from wallix/awless-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic_autoscaling_watching_CPU.aws
23 lines (16 loc) · 1.72 KB
/
dynamic_autoscaling_watching_CPU.aws
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Title: Group of instances scaling with CPU consumption
# Tags: infra, autoscaling
# Description: Create an autoscaling group of instances and watch their CPU to dynamically allocate/delete instances when needed.
# Create the instances launch configuration
launchconfig = create launchconfiguration image={instance.image} keypair={instance.keypair} name=scalingLaunchConf type={instance.type}
# Create the scalinggroup
create scalinggroup desired-capacity=2 launchconfiguration=$launchconfig max-size={instance.max-number} min-size={instance.min-number} name=instancesScalingGroup subnets={instance.subnets}
# Create a scaling policy to add instances (scale-in) and a scaling policy to remove instances (scale-out)
scalein = create scalingpolicy adjustment-scaling=1 adjustment-type=ChangeInCapacity name=policy-scaling-in scalinggroup=instancesScalingGroup
scaleout = create scalingpolicy adjustment-scaling=-1 adjustment-type=ChangeInCapacity name=policy-step-scaling-2 scalinggroup=instancesScalingGroup
# Add a monitoring alarm to enable scalein when CPU load is above 75% during 2 * 5 min
create alarm namespace=AWS/EC2 dimensions=AutoScalingGroupName:instancesScalingGroup evaluation-periods=2 metric=CPUUtilization name=scaleinAlarm operator=GreaterThanOrEqualToThreshold period=300 statistic-function=Average threshold=75
attach alarm name=scaleinAlarm action-arn=$scalein
# Add a monitoring alarm to enable scaleout when CPU load is below 75% during 2 * 5 min
create alarm namespace=AWS/EC2 dimensions=AutoScalingGroupName:instancesScalingGroup evaluation-periods=2 metric=CPUUtilization name=scaleoutAlarm operator=LessThanOrEqualToThreshold period=300 statistic-function=Average threshold=75
attach alarm name=scaleoutAlarm action-arn=$scaleout