0
0

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 5 years have passed since last update.

[JAWS-UG CLI] AutoScaling:#5 インスタンスの削減

Posted at

前提条件

AutoScalingへの権限

AutoScalingに対してフル権限があること。

AWS CLIのバージョン

以下のバージョンで動作確認済

  • AWS CLI 1.10.58
コマンド
aws --version

結果(例):

  aws-cli/1.10.58 Python/2.7.11 Darwin/15.6.0 botocore/1.4.48
  1. 準備
    =======

0.1. リージョンの決定

変数の設定
AWS_DEFAULT_REGION='ap-northeast-1'

0.2. 変数の確認:

プロファイルが想定のものになっていることを確認します。

変数の確認
aws configure list

結果(例):

        Name                    Value             Type    Location
        ----                    -----             ----    --------
     profile       ec2as_full-prjZ-mbp13        env    AWS_DEFAULT_PROFILE
  access_key     ****************XXXX shared-credentials-file
  secret_key     ****************XXXX shared-credentials-file
      region        ap-northeast-1        env    AWS_DEFAULT_REGION
  1. 事前作業
    ===========
変数の設定
AS_DESIRED_CAPACITY='1'
  1. インスタンスの削減
    =====================
変数の確認
cat << ETX

        AS_GROUP_NAME:       ${AS_GROUP_NAME}
        AS_DESIRED_CAPACITY: ${AS_DESIRED_CAPACITY}

ETX
コマンド
aws autoscaling set-desired-capacity \
        --auto-scaling-group-name ${AS_GROUP_NAME} \
        --desired-capacity ${AS_DESIRED_CAPACITY}

結果(例):

  (戻り値なし)
  1. 事後作業
    ===========
コマンド
aws autoscaling describe-auto-scaling-instances 

結果(例):

  {
    "AutoScalingInstances": [
      {
          "ProtectedFromScaleIn": false,
          "AvailabilityZone": "ap-northeast-1a",
          "InstanceId": "i-xxxxxxxx",
          "AutoScalingGroupName": "asgroup-handson-20160829",
          "HealthStatus": "HEALTHY",
          "LifecycleState": "Terminating",
          "LaunchConfigurationName": "launchcongig-handson-20160829"
      },
      {
          "ProtectedFromScaleIn": false,
          "AvailabilityZone": "ap-northeast-1c",
          "InstanceId": "i-xxxxxxxx",
          "AutoScalingGroupName": "asgroup-handson-20160829",
          "HealthStatus": "HEALTHY",
          "LifecycleState": "InService",
          "LaunchConfigurationName": "launchcongig-handson-20160829"
      }
    ]
  }

片方のインスタンスが "LifecycleState": "Terminating" になっていれば、
インスタンスの削減が成功しています。

コマンド
aws ec2 describe-instances \
        --filters Name=instance-state-name,Values=${EC2_INSTANCE_STATUS} \
        --query 'Reservations[].Instances[].InstanceId'

結果(例):

  [
    "i-xxxxxxxx"
  ]

完了

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?