Autoscaling group points to old version of launch template

0

Hello,

I'm creating a launch template and autoscaling group through cloud formation. The auto-scaling group is currently pointed to the DefaultVersion of the launch template, which is version 1. The latest version of the launch template is version 2. I updated the default version of the launch template to version 3, but I don't see it reflected in the auto-scaling group. I know we update the launch template version through instance refresh, but I would like to know if this is expected behavior to still see version 1 in the autoscaling group even though the default version is now version 2. I want to handle the updates through cloud formation.

The problem I'm trying to solve is how do I push changes through cloud formation and handle the updates gracefully in the auto-scaling group. For example - I have two autoscaling groups using the same launch template. Then I decide to update one auto-scaling group to have a different ami. There will be two versions of the launch template, version 1 will have the old ami, and version 2 will have the latest ami. I'd like to gracefully roll out the changes to the autoscaling group 2 through cloud formation.

Question 1 - How can I change the auto-scaling group through cloud formation and replace instances gracefully? Question 2 - If I change the version number in the cloud formation template, does it terminate instances first and then redeploy the new ec2 or the other way around?

  • If you want different AMIs (or any other setting) between the 2 ASGs (AutoScaling Groups), its simplest to make a different Launch Template per ASG, and increment each ones versions when that specific ASG needs an update

2 Answers
1

Question 1 - How can I change the auto-scaling group through cloud formation and replace instances gracefully?

Question 2 - If I change the version number in the cloud formation template, does it terminate instances first and then redeploy the new EC2 or the other way around?

The answers to both of your questions depends on the UpdatePolicy being used for your AutoScaling Group. For example if you are using AutoScalingReplacing update policy, and set WillReplace: true, it will then replace the instances with older version launch templates by launching new instances with new Launch template versions. If this is set to False, then it will not replace the existing instances with older Launch template versions but when launching new instances from that point, it will make use of newer Launch template version.

In case you use AutoScalingRollingUpdate policy as UpdatePolicy, as the name suggests, Instances will be replaced in a rolling fashion according to the configured rolling policy configuration.

References: AutoScalingReplacing update policy: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatepolicy.html#cfn-attributes-updatepolicy-replacingupdate AutoScalingRollingUpdate policy: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatepolicy.html#cfn-attributes-updatepolicy-rollingupdate

AWS
SUPPORT ENGINEER
answered a year ago
0

Hi, @learner00

What are you specifying for AWS::AutoScaling::AutoScalingGroup.LaunchTemplateSpecification.Version ?

The Version specified in CloudFormation is a static value. So when you update your launch template, you should also update the Version of the LaunchTemplateSpecification at the same time.

profile picture
EXPERT
iwasa
answered a year ago
  • LaunchTemplate: LaunchTemplateSpecification: LaunchTemplateId: Ref: LaunchTemplate Version: !GetAtt LaunchTemplate.DefaultVersionNumber

  • yes. It gets the static version when you deploy CloudFormation, so you can't specify the version if you update the launch template outside of CloudFormation. To achieve this you need to specify Latest and Default outside of CloudFormation.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions