【发布时间】: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 集群。删除堆栈失败。