14

I'm experimenting with CloudFormation right now. I deployed a stack that included an AutoScalingGroup (and LaunchConfig and CloudFormation::Init), LoadBalancer, a single EC2 instance (and CloudFormation::Init), and a couple security groups.

If I terminate EC2 instances created by the AutoScalingGroup, they get recreated as expected. This is actually quite useful for testing changes to my LaunchConfiguration and CloudFormation::Init settings (basically making sure it works from scratch).

I also have an EC2 instance (named DnsServer1) that has a public IP. While working on its CloudFormation::Init data, I also manually terminated its instance. I know CloudFormation doesn't restore it like an AutoScalingGroup does, but I was expecting it would be recreated when I ran aws cloudformation update-stack.

Instead, I get the error: AWS::EC2::Instance DnsServer1 i-014eee8720c4fb542 does not exist.

Full update log:

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

What can I do to get CloudFormation to recreate this resource, short of deleting the stack and recreating it?

gregmac
  • 1,459
  • 3
  • 18
  • 27

2 Answers2

6

The easiest way is to give the EC2 instance a different resource name and update the stack. Cloudformation will interpret that as you creating an entirely new instance and create it.

Another alternative is to change a configuration value that forces the creation of a new instance, such as changing the subnet of the instance.

Peter Dolberg
  • 266
  • 1
  • 3
0

I faced similar issue related to unique ID, this link helped me to resolve the issue.

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

  • 4
    Thanks for the link, but links can go stale and then your post provides no value. Can you please edit your post to include some useful information about how you resolved the issue, even if it's just a high level outline. – Tim Oct 25 '19 at 06:01