无法使用CloudFormation删除Amazon ECS集群

ng1*_*404 6 aws-cloudformation

我正在使用以下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']
Run Code Online (Sandbox Code Playgroud)

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

我能够更早地删除堆栈,这个问题最近开始发生。有什么解决方法可以避免此问题?我是否需要添加一些依赖项?

小智 5

正如此 AWS 文档链接中提到的,您是否也尝试过取消注册实例?:

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

或者,您可以使用以下 AWS CLI 命令取消注册容器实例。请务必替换您要取消注册的每个容器实例的区域、集群名称和容器实例 ID。

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