amazon-web-servicesamazon-ec2aws-cloudformationaws-cdk

Force cloudformation to allocate a new EC2 instance


I am using CDK to deploy my application to EC2. For each version that I deploy - I would like a clean EC2 instance. This is a hard requirement, I am not interested in recycling the instance at all: I allways want a new instance (network adaptors, disks, and all)

The problem is that Cloudformation recycles my EC2 instance: It utilizes the same EC2 instance (same instance ID): Tried changing the <user_data> to a random value, and also the instance name.

Is there anything else I can use to force a restart?


Solution

  • This is clearly mentioned in the docs

    CDK uses CloudFormation which if you change the logical ID it will force cloud formation to recreate the resource

    Avoid changing the logical ID of a resource after it has been created. AWS CloudFormation identifies resources by their logical ID. Therefore, if you change the logical ID of a resource, AWS CloudFormation creates a new resource with the new logical ID, then deletes the existing one. Depending on the type of resource, this might cause service interruption, data loss, or both.