【问题标题】:Cannot Delete Amazon ECS Cluster using CloudFormation无法使用 CloudFormation 删除 Amazon ECS 集群
【发布时间】:2018-02-27 00:53:36
【问题描述】:

我正在使用以下 CloudFormation 模板来创建 ECS 集群。

AWSTemplateFormatVersion: '2010-09-09'
Description: 'AWS Cloudformation Template to create the Infrastructure'
Resources:
  ECSCluster:
    Type: AWS::ECS::Cluster
    Properties:
    ClusterName: 'Blog-iac-test-1'
  EC2InstanceProfile:
    Type: AWS::IAM::InstanceProfile
    Properties:
    Path: /
    Roles: [!Ref 'EC2Role']
  ECSAutoScalingGroup:
    Type: AWS::AutoScaling::AutoScalingGroup
  Properties:
    VPCZoneIdentifier:
    - subnet-****
    LaunchConfigurationName: !Ref 'ECSAutoscalingLC'
    MinSize: '1'
    MaxSize: '2'
    DesiredCapacity: '1'
 ECSAutoscalingLC:
    Type: AWS::AutoScaling::LaunchConfiguration
    Properties:
      AssociatePublicIpAddress: true
      ImageId: 'ami-b743bed1'
      SecurityGroups:
      - sg-****
      InstanceType: 't2.micro'
      IamInstanceProfile: !Ref 'EC2InstanceProfile'
      KeyName: 'test'
      UserData:
        Fn::Base64: !Sub |
        #!/bin/bash -xe
        echo ECS_CLUSTER=Blog-iac-test-1 >> /etc/ecs/ecs.config
  EC2Role:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
      Statement:
      - Effect: Allow
      Principal:
        Service: [ec2.amazonaws.com]
        Action: ['sts:AssumeRole']
      Path: /
  ECSServicePolicy:
    Type: "AWS::IAM::Policy"
    Properties: 
      PolicyName: "root"
      PolicyDocument: 
        Version: "2012-10-17"
        Statement: 
        - Effect: Allow
        Action: ['ecs:*', 'logs:*', 'ecr:*', 's3:*']
        Resource: '*'
    Roles: [!Ref 'EC2Role']

堆栈创建成功,但在销毁时,我收到以下错误:
当容器实例处于活动状态或耗尽时,无法删除集群。

我之前能够删除堆栈,这个问题最近开始出现。 有什么办法可以避免这个问题?我是否需要添加一些依赖项?

【问题讨论】:

  • 当您之前能够删除堆栈时,您是否有任何任务和服务在其上运行?我在您的任务定义中没有看到任何 ECS 服务,因此如果这些服务是在范围之外创建的,那么您可能需要在尝试销毁集群之前缩减这些服务和任务。
  • @JamieStarke 当我之前能够删除堆栈时,没有任何任务或服务在其上运行。即使是现在,我也没有任何任务或服务。在尝试破坏集群之前,我确实缩小了它们。
  • 嗯,如果它们完全扩展到 0,并且正在耗尽,那么我会联系 AWS Support,因为这是一个错误。也就是说,我打赌你缩小了它们,但它们并没有先耗尽。
  • 哦。为了测试,我使用上述模板创建了一个堆栈,并尝试在创建任何服务之前删除堆栈。同样的问题仍然存在。我认为这是一个错误,应该联系 AWS 支持。
  • 可以重现购买构建我自己的没有服务或容器的 ECS 集群。删除堆栈失败。

标签: amazon-cloudformation


【解决方案1】:

this AWS Documentation Link 中所述,您是否也尝试过注销实例?:

注销容器实例: 在您可以删除集群之前,您 必须取消注册该集群内的容器实例。对于每个 集群内的容器实例,请按照 注销一个容器实例来注销它。

或者,您可以使用以下 AWS CLI 命令取消注册 您的容器实例。一定要替换 Region、cluster 您创建的每个容器实例的名称和容器实例 ID 正在注销。

aws ecs deregister-container-instance --cluster default --container-instance container_instance_id --region us-west-2 --force

【讨论】:

    猜你喜欢
    • 2015-08-23
    • 1970-01-01
    • 2017-09-13
    • 1970-01-01
    • 2015-10-11
    • 2022-06-28
    • 1970-01-01
    • 1970-01-01
    • 2017-06-16
    相关资源
    最近更新 更多