LoginSignup
0
2

More than 5 years have passed since last update.

【AutoScalingGroup】スケールのスケジュール実行方法メモ

Posted at

スケジュールされた時間にスケールする

$ aws autoscaling put-scheduled-update-group-action \
  --scheduled-action-name scheduled-scale-out \
  --auto-scaling-group-name sample-auto-scale \
  --start-time "2017-12-10T14:00:00Z" \
  --desired-capacity 2

CloudWatchのメトリクスを元にスケールする

今回はCPU使用率をメトリクスに以下のルールでスケールするように設定します。

CPU使用率 アクション
70 <= CPUUtilization < 80 現在のインスタンス数から10%増やす
80 <= CPUUtilization < 90 現在のインスタンス数から20%増やす
90 <= CPUUtilization (90%以上) 現在のインスタンス数から30%増やす

ScalingPolicyを作成する

$ aws autoscaling put-scaling-policy \
  --auto-scaling-group-name sample-auto-scale \
  --policy-name sample-auto-scale-step-policy \
  --policy-type StepScaling \
  --adjustment-type PercentChangeInCapacity \
  --metric-aggregation-type Average \
  --step-adjustments MetricIntervalLowerBound=10.0,MetricIntervalUpperBound=20.0,ScalingAdjustment=10 \
                     MetricIntervalLowerBound=20.0,MetricIntervalUpperBound=30.0,ScalingAdjustment=20 \
                     MetricIntervalLowerBound=30.0,ScalingAdjustment=30 \
  --min-adjustment-magnitude 1

--step-adjustmentsのパラメータですが、

API または CLI を使用している場合は、違反しきい値と相対的に上限と下限を指定します。

なので、CloudWatch Alarmの閾値を60%にする想定で、差分を指定しています。
例えば、CPU使用率70%以上80未満の指定は MetricIntervalLowerBound=10.0,MetricIntervalUpperBound=20.0のように行っています。

CloudWatch Alarmを設定する

$ aws cloudwatch put-metric-alarm \
  --alarm-name sample-auto-scale-out-alarm \
  --metric-name CPUUtilization --namespace AWS/EC2 \
  --statistic Average \
  --threshold 60 --comparison-operator GreaterThanOrEqualToThreshold \
  --period 180 --evaluation-periods 1 \
  --dimensions "Name=AutoScalingGroupName,Value=sample-auto-scale" \
  --alarm-actions arn:aws:autoscaling:us-west-2:999999999999:scalingPolicy:xxxxxxxx-yyyy-zzzz-aaaa-999999999999:autoScalingGroupName/sample-auto-scale:policyName/sample-auto-scale-step-policy

対象のAutoScalingGroupを --dimensionsで指定します。
またこのアラームで作成したScalingPolicyを呼び出して欲しいので --alarm-actionsで先ほど作成したScalingPolicyのARNを指定します。
またScalingPolicy作成時に閾値を60に想定して差分指定していたので--thresholdを60に指定します。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2