ECS resources cannot be imported into CloudFormation

1

When I try to import ecs resources (cluster, task definition and service) using CloudFormation console, I got an error like

Resource handler returned message: "Invalid request provided: DescribeServices error: Invalid identifier: Identifier is for cluster MyECSCluster. Your cluster is default (Service: AmazonECS; Status Code: 400; Error Code: InvalidParameterException; Request ID: xxxxxxxxx; Proxy: null)" (RequestToken: xxxxxxxxx, HandlerErrorCode: InvalidRequest)

I got this error after all the resources imports succeeded. The cluster update also succeeded. The failure occurs in the ECS service update. I used CLI to create the cluster and the service. For the task definition, I used existing one so I don't remember how it was created. I also tried to create a cluster (only cluster itself, not task def and service) by management console and cloudformation because the cluster is created on cloudformation (When I create a cluster by CLI, the cluster is not created on cloudformation). However, I got the similar error which says

... Your cluster is default ...

How can I solve this? Is there any way to create a non-default cluster?

My existing cluster and its service are working properly and template used for the import is

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
      "ECSCluster": {
          "Type": "AWS::ECS::Cluster",
          "DeletionPolicy": "Delete"
      },
      "ECSTaskDefinition": {
        "Type": "AWS::ECS::TaskDefinition",
        "DeletionPolicy": "Retain"
      },
      "ECSService": {
        "Type": "AWS::ECS::Service",
        "DeletionPolicy": "Delete"
      }
  }
}  

Thanks,

1 Antwort
1

I solved this problem by adding Cluster property to ECS service resource. Since I didn't specify the property, the default cluster was assumed. I changed the template to

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
      "ECSCluster": {
          "Type": "AWS::ECS::Cluster",
          "DeletionPolicy": "Delete"
      },
      "ECSTaskDefinition": {
        "Type": "AWS::ECS::TaskDefinition",
        "DeletionPolicy": "Retain"
      },
      "ECSService": {
        "Type": "AWS::ECS::Service",
        "DeletionPolicy": "Delete"
        "Properties": {
           "Cluster": "MyECSCluster"
        }
      }
  }
}  

and now import is working properly.

beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen