如何让 AWS CloudFormation 重新创建我手动删除的资源?

gre*_*mac 11 amazon-web-services amazon-cloudformation

我现在正在试验 CloudFormation。我部署了一个堆栈,其中包括一个 AutoScalingGroup(以及 LaunchConfig 和 CloudFormation::Init)、LoadBalancer、一个 EC2 实例(和 CloudFormation::Init)和几个安全组。

如果我终止由 AutoScalingGroup 创建的 EC2 实例,它们会按预期重新创建。这对于测试我的 LaunchConfiguration 和 CloudFormation::Init 设置的更改实际上非常有用(基本上确保它从头开始工作)。

我还有一个DnsServer1具有公共 IP的 EC2 实例(名为)。在处理它的 CloudFormation::Init 数据时,我还手动终止了它的实例。我知道 CloudFormation 不会像 AutoScalingGroup 那样恢复它,但我希望在我运行aws cloudformation update-stack.

相反,我收到错误:AWS::EC2::Instance DnsServer1 i-014eee8720c4fb542 does not exist

完整更新日志:

11:03:40 UTC-0500   UPDATE_ROLLBACK_COMPLETE    AWS::CloudFormation::Stack  GregCFTest1 
11:03:38 UTC-0500   UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS    AWS::CloudFormation::Stack  GregCFTest1 
11:03:36 UTC-0500   UPDATE_COMPLETE AWS::AutoScaling::LaunchConfiguration   WebServerLaunchConfig   
11:03:36 UTC-0500   UPDATE_COMPLETE AWS::EC2::Instance  DnsServer1  
11:03:13 UTC-0500   UPDATE_ROLLBACK_IN_PROGRESS AWS::CloudFormation::Stack  GregCFTest1 The following resource(s) failed to update: [DnsServer1].
11:03:11 UTC-0500   UPDATE_COMPLETE AWS::AutoScaling::LaunchConfiguration   WebServerLaunchConfig   
11:03:10 UTC-0500   UPDATE_FAILED   AWS::EC2::Instance  DnsServer1  i-014eee8720c4fb542 does not exist
11:03:00 UTC-0500   UPDATE_IN_PROGRESS  AWS::CloudFormation::Stack  GregCFTest1 User Initiated
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能让 CloudFormation 重新创建此资源,而不是删除堆栈并重新创建它?

小智 5

最简单的方法是为 EC2 实例提供不同的资源名称并更新堆栈。Cloudformation 会在您创建一个全新的实例并创建它时进行解释。

另一种替代方法是更改​​强制创建新实例的配置值,例如更改实例的子网。