Help us understand the problem. What is going on with this article?

[JAWS-UG CLI] ELB:#5 ロードバランサの削除

More than 3 years have passed since last update.

前提条件

ELBへの権限

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

EC2への権限

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

AWS CLIのバージョン

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

  • AWS CLI 1.10.58
コマンド
aws --version
結果(例)
      aws-cli/1.10.63 Python/2.7.11 Darwin/15.6.0 botocore/1.4.53

バージョンが古い場合は最新版に更新しましょう。

コマンド
sudo -H pip install -U awscli

0. 準備

0.1. リージョンの決定

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

0.2. 変数の確認:

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

変数の確認
aws configure list
結果(例)
            Name                    Value             Type    Location
            ----                    -----             ----    --------
         profile       ec2elb_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

0.3. ロードバランサ名の指定

変数の設定
ELB_LB_NAME='lb-handson-20160912'

1. 事前作業

1.1. 削除対象のロードバランサの確認

コマンド
aws elb describe-load-balancers \
        --load-balancer-names ${ELB_LB_NAME}
結果(例)
      {
        "LoadBalancerDescriptions": [
          {
              "Subnets": [
                  "subnet-xxxxxxxx",
                  "subnet-xxxxxxxx"
              ],
              "CanonicalHostedZoneNameID": "xxxxxxxxxxxx",
              "CanonicalHostedZoneName": "lb-handson-20160912-xxxxxxxx.ap-northeast-1.elb.amazonaws.com",
              "ListenerDescriptions": [
                  {
                      "Listener": {
                          "InstancePort": 80,
                          "LoadBalancerPort": 80,
                          "Protocol": "HTTP",
                          "InstanceProtocol": "HTTP"
                      },
                      "PolicyNames": []
                  }
              ],
              "HealthCheck": {
                  "HealthyThreshold": 10,
                  "Interval": 30,
                  "Target": "TCP:80",
                  "Timeout": 5,
                  "UnhealthyThreshold": 2
              },
              "VPCId": "vpc-xxxxxxxx",
              "BackendServerDescriptions": [],
              "Instances": [],
              "DNSName": "lb-handson-20160912-xxxxxxxx.ap-northeast-1.elb.amazonaws.com",
              "SecurityGroups": [
                  "sg-xxxxxxxx"
              ],
              "Policies": {
                  "LBCookieStickinessPolicies": [],
                  "AppCookieStickinessPolicies": [],
                  "OtherPolicies": []
              },
              "LoadBalancerName": "lb-handson-20160912",
              "CreatedTime": "2016-09-12T01:23:45.678Z",
              "AvailabilityZones": [
                  "ap-northeast-1a",
                  "ap-northeast-1c"
              ],
              "Scheme": "internet-facing",
              "SourceSecurityGroup": {
                  "OwnerAlias": "XXXXXXXXXXXX",
                  "GroupName": "ec2-http-https-global-inbound"
              }
          }
        ]
      }

2. ロードバランサの削除

変数の確認
cat << ETX

        ELB_LB_NAME: ${ELB_LB_NAME}

ETX
コマンド
aws elb delete-load-balancer \
        --load-balancer-name ${ELB_LB_NAME}
結果
      (戻り値なし)

3. 事後作業

同名のロードバランサが存在しないことを確認します。

コマンド
aws elb describe-load-balancers \
        --load-balancer-names ${ELB_LB_NAME}
結果
      A client error (LoadBalancerNotFound) occurred when calling the DescribeLoadBalancers operation: Cannot find Load Balancer lb-handson-20160912

完了

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away