LoginSignup
1
0

More than 1 year has passed since last update.

AWS Cloud Map を CDK で 作成したりを繰り返していたら、Service already exists って言われた時

Posted at

現象

Service [srv-xxxxxxxxxxxxxxxx] already exists

みたいなエラーが出ますが、Management Console から何を削除しようにもどこに何があるかわからなかったので、aws-cli servicediscoveryの出番でした。

手順

私は以下のようにして、リソースを削除しました。

1. サービスに紐づくインスタンス一覧を取得

サービスを削除する前に、登録してあるインスタンスを削除する必要があるようでした。

ですので、list-instances コマンドに、エラー分にあったservice idを--service-idオプションに渡して、インスタンス一覧を表示します。

$ aws servicediscovery list-instances --service-id srv-xxxxxxxxxxxxxxxx

以下のようにインスタンスの一覧が返ってきます。(ここでは便宜上1件)

{
    "Instances": [
        {
            "Id": "xxxxxxxxxxxxxxxxxxxxxxx",
            "Attributes": {
                "AVAILABILITY_ZONE": "ap-northeast-1c",
                "AWS_INIT_HEALTH_STATUS": "UNHEALTHY",
                "AWS_INSTANCE_IPV4": "10.2.1.253",
                "ECS_CLUSTER_NAME": "Cluster",
                "ECS_SERVICE_NAME": "Service",
                "ECS_TASK_DEFINITION_FAMILY": "TaskDefinition",
                "REGION": "ap-northeast-1"
            }
        }
    ]
}

2. インスタンスの登録を解除

deregister-instanceコマンドを使用します。

レスポンスのJSONの中のInstances.Idの値を--instance-id 引数に渡し登録を解除。

$ aws servicediscovery deregister-instance --service-id srv-xxxxxxxxxxxxxxxx --instance-id xxxxxxxxxxxxxxxxxxxxxxx

以上で登録解除できたはずです。

3. サービスを削除

list-instancesでも使用したservice idでdelete-serviceコマンドを使用してサービスが削除できます。

$ aws servicediscovery delete-service --service-id srv-xxxxxxxxxxxxxxxx

以上です。

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