AndrewGuenther / cdk-fck-nat

CDK constructs for the fck-nat service
MIT License
63 stars 9 forks source link

InstanceType not updating after changing #307

Open qmitchell-aa opened 6 months ago

qmitchell-aa commented 6 months ago

Hi,

Wanted to highlight this situation to be potentially helpful to others , if they find themselves in the same situation as me.

My usage of fck-nat is below. If I change the instanceType, then my instance does not update / stays at the old instance type.

return new FckNatInstanceProvider({
      eipPool: [eip.attrAllocationId],
      instanceType,
      machineImage: new ec2.GenericLinuxImage(image),
      enableSsm: false,
    });

I think I'm in a similar situation as to this: https://www.reddit.com/r/aws/comments/136xaiz/ecs_container_instance_not_updating_when_launch/

Due to the launchtemplate changing and not actually the instance definition, therefore my currently running instance isn't changed.

I wasn't familiar with launch templates & ASGs ... this issue made me learn them a little.

The fix

  1. Go to the ASG, click it's launch template. Set the next version as the default version.
  2. Go to the ASG, click Instance Refresh tab. Start a refresh with "Launch before terminating". I kept all default settings, but gave the instance 10 seconds for instance warm up.
  3. Wait a bit, new instance will start, warmup, then old instance will go away.

To the maintainer, maybe close this issue as it is by CDK design to work like this. Just quirky 'by design' place we've found ourselves in.

AndrewGuenther commented 2 months ago

Sorry for taking so long to respond. I think it would be worth plumbing the ASG UpdatePolicy (https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.UpdatePolicy.html) through to the FckNatProvider to let people customize this. By default, CDK will not update instances as part of an ASG update, but that can be configured. Personally, I think this is a good behavior, but I think it's sensible to surface this option to users directly.