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

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

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

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

我还有一个具有公共 IP 的 EC2 实例(名为DnsServer1)。在处理其 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

除了删除堆栈并重新创建之外,我该怎么做才能让 CloudFormation 重新创建此资源?

答案1

最简单的方法是为 EC2 实例指定一个不同的资源名称并更新堆栈。Cloudformation 会将其解释为您创建一个全新的实例并创建它。

另一种选择是更改强制创建新实例的配置值,例如更改实例的子网。

答案2

我遇到了与唯一 ID 相关的类似问题,此链接帮助我解决了该问题。

https://aws.amazon.com/premiumsupport/knowledge-center/failing-stack-updates-deleted/

相关内容