Remediation
Follow these steps to migrate an Auto Scaling Group from a legacy Launch Configuration to a Launch Template.
From Command Lineβ
Export the Existing Launch Configurationβ
aws autoscaling describe-launch-configurations \
--launch-configuration-names {{launch-configuration-name}} \
--query 'LaunchConfigurations[0]' \
--output json > {{lc-export.json}}
Note: Modify the JSON schema to match the Launch TempTemplate since the configuration object includes extra fields that EC2βs create-launch-template
will reject, and some keys need renaming.
Create the Launch Templateβ
aws ec2 create-launch-template \
--launch-template-name {{launch-template-name}} \
--version-description {{version-description}} \
--launch-template-data file://{{lc-export.json}}
Update the Auto Scaling Group to Use the Launch Templateβ
aws autoscaling update-auto-scaling-group \
--auto-scaling-group-name {{asg-name}} \
--launch-template LaunchTemplateId={{launch-template-id}},Version='$Latest'
After this update, any new instances will be provisioned using the new Launch Template.
Replace Existing Instances (Optional)β
To roll out the new template across all running instances, initiate an Instance Refresh:
-
Create a JSON file (
{{config.json}}
) with your preferences.Example of
config.json
:
"AutoScalingGroupName": "asg-name",
"Preferences": {
"InstanceWarmup": 60,
"MinHealthyPercentage": 50,
"AutoRollback": true,
"ScaleInProtectedInstances": Ignore,
"StandbyInstances": Terminate
}
}
- Start the instance refresh:
aws autoscaling start-instance-refresh \
--cli-input-json file://{{config.json}}