1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AWS CLIでAuto Scaling グループの「希望する容量、最小キャパシティ、最大キャパシティ」を変更する

Posted at

はじめに

ローカルPCからAWS CLIを利用して、Auto Scaling グループの希望する容量、最小キャパシティ、最大キャパシティを変更します。
コスト削減のため、利用しない時は値を0にすると思いますが、AWS CLIで変更します。

スクリプト

1. オートスケーリングに紐づくEC2インスタンスを起動する

start_auto_scaling_groups.sh
#!/bin/sh
   
cd `dirname $0`

start_asg () {

    ASG_NAME=$1
    SIZE=$2
    MAX_SIZE=${SIZE}
    MIN_SIZE=${SIZE}
    DESIRED_CAPACITY=${SIZE}
    echo "start auto scaling group: ${ASG_NAME}"

    aws autoscaling update-auto-scaling-group \
    --auto-scaling-group-name ${ASG_NAME} \
    --max-size ${MAX_SIZE} \
    --min-size ${MIN_SIZE} \
    --desired-capacity ${DESIRED_CAPACITY} \
    --profile ${AWS_PROFILE}

}

start_asg [GROUP_NAME] 2

2. オートスケーリングに紐づくEC2インスタンスを停止する

stop_auto_scaling_groups.sh
#!/bin/sh

cd `dirname $0`

stop_asg () {

    ASG_NAME=$1
    MIN_SIZE=0
    DESIRED_CAPACITY=0
    echo "stop auto scaling group: ${ASG_NAME}"

    aws autoscaling update-auto-scaling-group \
    --auto-scaling-group-name ${ASG_NAME} \
    --min-size ${MIN_SIZE} \
    --desired-capacity ${DESIRED_CAPACITY} \
    --profile ${AWS_PROFILE}

}

stop_asg [GROUP_NAME]

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?