0Pricing
AWS Solutions Architect · Lesson

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.

Launch Templates and ASG Configuration is a free AWS Solutions Architect lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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"
  }'

Launch Template Versions and Defaults

Every Launch Template starts at version 1. When you create a new version you can override only the fields that changed—all other settings are inherited from the source version. The ASG can be told to use a $Latest version (always the newest) or a $Default version (explicitly designated). Using $Default gives you controlled rollouts, while $Latest is convenient in dev environments.

# Create a new version based on version 1, changing only instance type
aws ec2 create-launch-template-version \
  --launch-template-name 'MyAppTemplate' \
  --source-version 1 \
  --launch-template-data '{"InstanceType": "t3.large"}'

Auto Scaling Group Core Concepts

An Auto Scaling Group (ASG) maintains a fleet of EC2 instances within defined boundaries: minimum (floor), maximum (ceiling), and desired capacity (target count at any moment). When instances fail health checks or the scaling policy fires, ASG automatically launches or terminates instances to keep the fleet at the desired count between min and max.

Creating an ASG Attached to a Launch Template

When you create an ASG you reference a Launch Template (not a specific AMI directly). You also specify the VPC subnets where instances will be launched. Spreading across multiple subnets (one per AZ) gives you built-in multi-AZ redundancy—if one AZ fails, ASG launches replacement instances in the remaining AZs automatically.

aws autoscaling create-auto-scaling-group \
  --auto-scaling-group-name 'MyAppASG' \
  --launch-template 'LaunchTemplateName=MyAppTemplate,Version=$Default' \
  --min-size 2 \
  --max-size 10 \
  --desired-capacity 4 \
  --vpc-zone-identifier 'subnet-aaa111,subnet-bbb222,subnet-ccc333'

ASG Health Checks: EC2 vs ELB

By default an ASG uses EC2 health checks, which only flag an instance as unhealthy if it is stopped, terminated, or the hypervisor reports it failed. When you attach a load balancer you should switch to ELB health checks so the ASG replaces instances that are running but returning HTTP 5xx errors. This is a common exam question: always choose ELB health checks when there is a load balancer in the architecture.

# Enable ELB health checks on an existing ASG
aws autoscaling update-auto-scaling-group \
  --auto-scaling-group-name 'MyAppASG' \
  --health-check-type ELB \
  --health-check-grace-period 300

Capacity Settings: Min, Max, Desired

Setting the correct capacity bounds is critical. The minimum ensures your application can always serve traffic (never go below this). The maximum prevents runaway scaling that could exhaust service limits or budget. The desired capacity is the initial target; scaling policies adjust it dynamically. If you set min=max=desired, the ASG acts as a fixed-size group, which is useful for launch template deployments or pinned capacity.

Attaching an ALB Target Group to ASG

For web-tier applications, attach the ASG to an Application Load Balancer target group. Each new instance launched by the ASG is automatically registered with the target group, and terminated instances are automatically deregistered. This ensures traffic only flows to healthy, running instances. You must also set the health check type to ELB so the ASG is aware of load-balancer-level failures.

aws autoscaling attach-load-balancer-target-groups \
  --auto-scaling-group-name 'MyAppASG' \
  --target-group-arns 'arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/MyTG/abc123'

User Data in Launch Templates

User data is a shell script (Base64-encoded) that runs once when an instance first boots. In a Launch Template it is the right place to install packages, configure agents (CloudWatch, SSM), and pull application code. Keep user data idempotent—scripts that can run safely more than once prevent issues during instance refresh. For complex setups, call out to AWS Systems Manager or a configuration management tool instead of embedding large scripts.

#!/bin/bash
yum update -y
yum install -y amazon-cloudwatch-agent
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
  -a fetch-config -m ec2 -c ssm:/MyApp/CWConfig -s
# Start application
cd /opt/myapp && ./start.sh

Warm Pools for Faster Scale-Out

A Warm Pool pre-initialises a set of stopped (or running) EC2 instances in a ready state outside the ASG. When the ASG needs to scale out, it pulls from the warm pool instead of launching cold instances—dramatically reducing the time needed to add capacity. Instances in the warm pool incur stopped-state costs (EBS only, no CPU charges), making this much cheaper than keeping fully running spares.

Termination Policies and AZ Balance

When the ASG scales in it must decide which instances to terminate. The default termination policy selects the AZ with the most instances first (to rebalance), then the oldest launch template, then the instance closest to its billing hour. You can customise this order—for example, choose OldestLaunchTemplate to remove instances running outdated configurations first. ASG also performs AZ rebalancing automatically after a subnet becomes available or after manual changes.

Quick Check

Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.

Lesson Recap

In this lesson you learned: Launch Templates provide a versioned, reusable instance blueprint that supports multiple versions and $Latest/$Default version pointers, ASG capacity bounds (min/max/desired) govern fleet size with automatic multi-AZ distribution across subnets, and ELB health checks must be enabled when an ASG is behind a load balancer so application-level failures trigger replacement. Next up we explore scaling policies including target tracking and step scaling.

Frequently asked questions

Is the “Launch Templates and ASG Configuration” lesson free?

Yes — the full text of “Launch Templates and ASG Configuration” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.

What will I learn in “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. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AWS Solutions Architect?

No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Launch Templates and ASG Configuration” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AWS Solutions Architect lesson?

Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Launch Templates and ASG Configuration
  2. Scaling Policies: Target Tracking and Step Scaling
  3. Scheduled Scaling and Predictive Scaling
  4. Instance Refresh and Lifecycle Hooks
← Back to AWS Solutions Architect