Launch Templates and ASG Configuration
Create a launch template with the correct AMI, instance type, and user data, then attach it to an Auto Scaling Group with min, max, and desired capacity.
What Is a Launch Template?
A Launch Template is a versioned blueprint that tells Auto Scaling Groups (and EC2 directly) how to launch instances. It captures the AMI ID, instance type, key pair, security groups, and optional user data in a single reusable document. Unlike the older Launch Configuration, a Launch Template supports multiple versions and can be updated without replacing the ASG.
Creating a Launch Template via CLI
You can create a Launch Template with the AWS CLI using create-launch-template. The --launch-template-data parameter accepts a JSON object that defines all instance settings. Versioning lets you iterate on the template without affecting running instances until you are ready to deploy.
aws ec2 create-launch-template \
--launch-template-name 'MyAppTemplate' \
--version-description 'v1 initial' \
--launch-template-data '{
"ImageId": "ami-0abcdef1234567890",
"InstanceType": "t3.medium",
"KeyName": "my-key-pair",
"SecurityGroupIds": ["sg-0123456789abcdef0"],
"UserData": "IyEvYmluL2Jhc2gKZWNobyAnSGVsbG8n"
}'All lessons in this course
- Launch Templates and ASG Configuration
- Scaling Policies: Target Tracking and Step Scaling
- Scheduled Scaling and Predictive Scaling
- Instance Refresh and Lifecycle Hooks