更新失败后无法编辑 CloudFormation 堆栈?

Can't edit CloudFormation stack after failed update?

我的 CloudFormation 堆栈似乎爆炸了。我尝试快速更改以调整 EC2 实例的大小,但更新失败并出现错误:

Invalid value 'm4.large' for instanceType. LaunchPlan instance type does not match attribute value m4.xlarge

回滚也失败并出现错误:

The following resource(s) failed to update: [TC2, TC1, TC3].

我在右键单击堆栈时唯一的选择是删除,并尝试通过操作菜单强制继续更新会产生:

This instance 'i-e5e8b063' is not in a state from which it can be stopped.

查看 EC2 实例控制台,我可以看到这条消息至少是正确的:所有实例都列为已终止。

此处关于如何处理失败更新的所有建议似乎都基于我实际上能够修改堆栈以首先修复错误,而我无法做到:http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/troubleshooting.html#troubleshooting-errors-update-rollback-failed

除了清除堆栈并从我的备份中设计一个新堆栈之外,我还有什么办法吗?我完全不知所措。

CloudFormation 尝试声明式,并尝试能够从您开始的任何地方移动到模板中的状态。有时,它会进入不一致状态(当给定错误模板或在 CloudFormation 之外进行手动更改时)。当我遇到这种情况时,CloudFormation 通常会正确回滚,但如果没有,我只成功删除堆栈并从头开始。

因此,CloudFormation 中有两点很重要:

  1. 使用多层。例如,一个 FooDev 和一个 FooProd CloudFormation 堆栈,这样您就可以在 Dev 中测试(尤其是升级等)而不是破坏 Prod。
  2. 使用多个堆栈。例如,你的数据库堆栈应该是长期存在的并且是有状态的,所以它可能会得到自己的堆栈,你应该小心使用它们,而你的 EC2 实例应该是短暂存在的并且是无状态的,所以如果你搞砸了一个部署其中之一。

这些最佳实践以及其他最佳实践在 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/best-practices.html

中有详细说明