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개 답변
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.

답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠