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?
3
Answers
I’m not familiar with CDK, but the following approach is what I am using:
This way, Autoscaling automatically takes care of launching a new instance, shifting traffic to the new instance (since we use ALB as well), basically it automatically manages a rollout deployment.
Change the construct ID (the second argument when creating an
Instance
) – this will force resource replacement.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