- Newest
- Most votes
- Most comments
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
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.
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.
Relevant content
- Accepted Answerasked 2 years ago
- asked 5 years ago
- asked 3 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 10 months ago
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