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

[JAWS-UG CLI] ElastiCache #3 キャッシュクラスタの削除 (Redis編)

More than 3 years have passed since last update.

前提条件

ElastiCacheへの権限

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

AWS CLI

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

  • AWS CLI 1.10.44
コマンド
aws --version
結果(例)
      aws-cli/1.10.44 Python/2.7.11 Darwin/15.5.0 botocore/1.4.34

0. 準備

0.1. 変数の確認

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

変数の確認
aws configure list
結果(例)
            Name                    Value             Type    Location
            ----                    -----             ----    --------
         profile       elasticache-prjx-mbpr13        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.2. 削除対象クラスタ名の指定

変数の設定
ECACHE_CLUSTER_ID="handson-$(date +%Y%m%d)" \
      && echo ${ECACHE_CLUSTER_ID}

1. 事前作業

削除対象の確認

コマンド
aws elasticache describe-cache-clusters \
        --cache-cluster-id ${ECACHE_CLUSTER_ID}
結果(例)
      {
        "CacheClusters": [
          {
              "Engine": "redis",
              "CacheParameterGroup": {
                  "CacheNodeIdsToReboot": [],
                  "CacheParameterGroupName": "default.redis2.8",
                  "ParameterApplyStatus": "in-sync"
              },
              "CacheClusterId": "handson-20160704",
              "CacheSecurityGroups": [],
              "NumCacheNodes": 1,
              "CacheClusterCreateTime": "2016-07-04T01:23:45.678Z",
              "AutoMinorVersionUpgrade": true,
              "CacheClusterStatus": "available",
              "PreferredAvailabilityZone": "ap-northeast-1a",
              "ClientDownloadLandingPage": "https://console.aws.amazon.com/elasticache/home#client-download:",
              "SecurityGroups": [
                  {
                      "Status": "active",
                      "SecurityGroupId": "sg-xxxxxxxx"
                  }
              ],
              "CacheSubnetGroupName": "subnet-group-handson-20160704",
              "EngineVersion": "2.8.24",
              "PendingModifiedValues": {},
              "PreferredMaintenanceWindow": "sun:11:00-sun:12:00",
              "CacheNodeType": "cache.t2.micro"
          }
        ]
      }

2. キャッシュクラスターの削除

変数の確認
cat << ETX

        ECACHE_CLUSTER_ID: ${ECACHE_CLUSTER_ID}

ETX
コマンド
aws elasticache delete-cache-cluster \
        --cache-cluster-id ${ECACHE_CLUSTER_ID}
結果(例)
      {
        "CacheCluster": {
          "Engine": "redis",
          "CacheParameterGroup": {
              "CacheNodeIdsToReboot": [],
              "CacheParameterGroupName": "default.redis2.8",
              "ParameterApplyStatus": "in-sync"
          },
          "CacheClusterId": "handson-20160704",
          "CacheSecurityGroups": [],
          "NumCacheNodes": 1,
          "CacheClusterCreateTime": "2016-07-04T0l:23:45.678Z",
          "AutoMinorVersionUpgrade": true,
          "CacheClusterStatus": "deleting",
          "PreferredAvailabilityZone": "ap-northeast-1a",
          "ClientDownloadLandingPage": "https://console.aws.amazon.com/elasticache/home#client-download:",
          "SecurityGroups": [
              {
                  "Status": "active",
                  "SecurityGroupId": "sg-161efe72"
              }
          ],
          "CacheSubnetGroupName": "subnet-group-handson-20160704",
          "EngineVersion": "2.8.24",
          "PendingModifiedValues": {},
          "PreferredMaintenanceWindow": "sun:11:00-sun:12:00",
          "CacheNodeType": "cache.t2.micro"
        }
      }

3. 事後作業

3.1. ステータスの確認

コマンド
ECACHE_CLUSTER_STATUS=$( \
        aws elasticache describe-cache-clusters \
          --cache-cluster-id ${ECACHE_CLUSTER_ID} \
          --query 'CacheClusters[].CacheClusterStatus' \
          --output text \
) && echo ${ECACHE_CLUSTER_STATUS}
結果(例)
      deleting

3.2. キャッシュクラスター不存在の確認

削除に5-10分ほどかかります。

コマンド
aws elasticache describe-cache-clusters \
        --cache-cluster-id ${ECACHE_CLUSTER_ID}
結果(例)
      An error occurred (CacheClusterNotFound) when calling the DescribeCacheClusters operation: CacheCluster not found: handson-20160704

3.3. イベントの確認

変数の設定
MAX_ITEMS='2'
コマンド
aws elasticache describe-events \
        --query "Events[?SourceIdentifier == \`${ECACHE_CLUSTER_ID}\`]" \
        --max-items ${MAX_ITEMS}
結果(例)
      {
        "Events": [
          {
              "Date": "2016-07-04T01:23:45.678Z",
              "Message": "Cache cluster deleted",
              "SourceIdentifier": "handson-20160704",
              "SourceType": "cache-cluster"
          },
          {
              "Date": "2016-07-04T01:23:45.678Z",
              "Message": "Removed cache nodes 0001",
              "SourceIdentifier": "handson-20160704",
              "SourceType": "cache-cluster"
          }
        ]
      }

完了

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