当 AutoScaling 组的desiredCapacity 为 0 时,AWS ECS 不会启动 EC2 实例
场景 1:
我已按顺序创建了以下资源:
- 创建 AutoScalingGroup/ASG(使用 minCapacity 1)
- 创建 ECS 集群
- 将 AutoScalingGroup 作为提供程序附加到 ECS
在这种情况下我面临的问题是,EC2 获取由 ASG 启动,但不会连接到 ECS,因为 ECS_CLUSTER 值与实际集群名称不同。这感觉很明显,因为 ASG 是在提供者添加到集群之前启动的。
场景 2:
- 创建 AutoScalingGroup/ASG(minCapacity 0、desiredCapacity 0)
- 创建 ECS 集群
- 将 AutoScalingGroup 作为提供程序附加到 ECS
- 添加任务定义并创建服务
由于出现错误,服务无法启动:“否”在您的集群中找到了容器实例”
场景 2 让我感到困惑 - 不清楚 ECS 扩展策略是否也会创建第一个实例?
一些解决方案建议将最小容量保持为 1,以便它起作用。但如果我这样做,我最终会陷入场景 1,其中第一个 EC2 实例无法向 ECS 注册。
Scenario 1:
I have created the following resources in the order:
- Create AutoScalingGroup/ASG (with minCapacity 1)
- Create ECS Cluster
- Attach AutoScalingGroup as Provider to ECS
The problem I face in this case is, an EC2 gets launched by ASG and that doesn't connect to ECS because ECS_CLUSTER value is different from the actual cluster name. This feels obvious because ASG is launched before provider is added to cluster.
Scenario 2:
- Create AutoScalingGroup/ASG (with minCapacity 0, desiredCapacity 0)
- Create ECS Cluster
- Attach AutoScalingGroup as Provider to ECS
- Add a Task Def and create a Service
The service cannot launch because of an error: "No Container Instances were found in your cluster"
Scenario 2 confuses me - It isn't clear if ECS Scaling Policy would create the very first instance too or not?
Some solutions propose to keep the min capacity as 1, so that it works. But if I do that, I end up into Scenario 1, where the first EC2 instance can't register with ECS.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

您必须在启动配置或模板中使用
user_data
才能正确设置 ECS 实例。这包括提供集群名称,如 AWS 文档中所述:You have to use
user_data
in your Launch Configuration or Template to correctly setup the instances for ECS. This includes providing a claster name as explained in AWS docs: