skip to Main Content

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


  1. I’m not familiar with CDK, but the following approach is what I am using:

    1. Configure Autoscaling for our EC2 workloads,
    2. Have Instance Refresh configured to listen to Tag changes, and
    3. For every new version of code, we updated the Tag value with the version number.

    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.

    Login or Signup to reply.
  2. Change the construct ID (the second argument when creating an Instance) – this will force resource replacement.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search