Skip to main content
This lesson walks through creating a Launch Template, using it to provision an Auto Scaling group (ASG), attaching an Application Load Balancer (ALB), and demonstrating how to scale in and out. Follow each step in order to build a resilient, highly available web tier on EC2. First, open the EC2 console and navigate to Launch Templates.
A screenshot of the Amazon Web Services EC2 console (United States — Ohio) showing the EC2 dashboard with a Resources summary panel and left-hand navigation menu. The Resources panel lists counts for items like instances, security groups, key pairs, and volumes.

1. Create a Launch Template

A launch template stores the configuration for EC2 instances (AMI, instance type, security groups, user data, and other options). Auto Scaling groups use a launch template to launch consistent instances. Steps:
  • Click Create launch template.
  • Provide a name (for example, my-template) and an optional description.
  • Choose an AMI. If your recent AMIs aren’t shown, pick one from Quick Start (Amazon Linux is a common choice).
A screenshot of the AWS EC2 "Create launch template" page showing the Amazon Machine Image (AMI) Quick Start options (Amazon Linux, macOS, Ubuntu, Windows, Red Hat, SUSE, Debian) and an AMI selection area. The browser top bar and AWS account/region info are visible.
  • Set the instance type to t3.micro (type “t3” in the dropdown to filter).
  • Leave Key pair (login) as default if you do not need to SSH into instances immediately.
  • Create or select a security group. Example configuration:
Open the Advanced details section and paste your user data script so it runs on instance boot. This example installs Apache (httpd), starts it, and writes a simple index page that displays the instance hostname:
If you use Amazon Linux 2023, the package manager is dnf instead of yum. Replace yum install -y httpd with dnf install -y httpd and adjust other package-manager commands accordingly.
After entering user data and required fields, create the launch template.
A screenshot of the AWS EC2 "Create launch template" summary page. It shows the selected AMI (Amazon Linux 2023), the instance type t3.micro, a new security group, and the "Create launch template" button.
When instances boot from this template, the user data will configure Apache and create an index page that shows Hi from <hostname> so you can identify which instance handled a request.

2. Create an Auto Scaling Group

Next, create an Auto Scaling group that uses the launch template to maintain a fleet of identical instances.
  • Go to Auto Scaling groups in the EC2 console and click Create Auto Scaling group.
  • Give the ASG a name (for example, my-asg) and select the launch template (choose the appropriate version).
  • Under network settings, select your VPC and choose multiple Availability Zones (e.g., 2a, 2b, 2c) for high availability.
  • Leave the Availability Zone distribution at the default Balanced — best effort.
A screenshot of the AWS EC2 console "Create Auto Scaling group" page showing the "Availability Zone distribution" options with "Balanced best effort" selected. Other choices like "Balanced only" and "Reservations Then Balanced" are also visible.

Attach an Application Load Balancer (ALB)

To distribute incoming HTTP traffic across the ASG instances, attach an ALB during ASG creation:
  • Choose Attach to a new load balancer.
  • Select Application Load Balancer.
  • Provide a name (e.g., my-elb).
  • Create a target group (for example, MyTargetGroup) with protocol HTTP and port 80.
Make sure:
  • The load balancer security group allows inbound HTTP (port 80).
  • The instance security group allows traffic from the load balancer on port 80 (or allow the load balancer’s security group).
A screenshot of the AWS EC2 console's "Create Auto Scaling group" page showing the Listeners and routing section with Protocol HTTP, Port 80, and a new target group named "MyTargetGroup." The browser UI and AWS navigation header are also visible.
Enable ELB health checks for the ASG so the load balancer reports instance health back to Auto Scaling. When the ALB reports an instance as unhealthy for the configured threshold, Auto Scaling can replace it.
A screenshot of the AWS EC2 console on the "Create Auto Scaling group" page. It shows health check options with "Turn on Elastic Load Balancing health checks" enabled and an informational box about Auto Scaling reacting to load balancer health checks.

Set ASG capacity (Min / Desired / Max)

Choose capacity values to control how many instances the ASG maintains. Example for this demo: Finish the wizard. The ASG will launch instances based on the launch template and register them with the target group.
Provisioning an ALB can take several minutes (typically 5–10 minutes). Refresh the Load Balancers page until the ALB status becomes active.

3. Verify the setup and access the app

Once the ALB is active:
  • Open the Load Balancers page.
  • Copy the ALB DNS name and open it in your browser:
http://ALB_DNS_NAME/ You should see the index page created by user data, for example: Hi from ip-172-31-30-195.us-east-2.compute.internal Refreshing the browser may show different hostnames as the ALB distributes traffic across healthy instances.
A screenshot of the AWS EC2 console showing the Load Balancers page for a load balancer named "MyLB" and its target group "MyTargetGroup." Two EC2 instances are listed as healthy on port 80 and the "Create load balancer" button is visible.
The ALB console and target group view display the listener (HTTP:80), the forwarding rule to the target group, and registered instances with health statuses.

4. Cleanup

To avoid ongoing charges, delete resources you no longer need in this order:
  • Delete the Auto Scaling group: select the ASG → Actions → Delete.
  • Delete the Load Balancer: select the load balancer → Actions → Delete.
This removes the ASG-managed instances and the ALB.

5. Manually scale an Auto Scaling group

You can manually change the ASG capacity through the console:
  • Select the ASG → Actions → Edit (or open the Details panel and click Edit).
  • Update the Desired, Min, and Max capacity values, then save.
A screenshot of the AWS EC2 Auto Scaling group "Edit" page showing Desired capacity set to 2 and Scaling limits with Min desired capacity 2 and Max desired capacity 3.
Example: scale out by setting Desired = 3 and Max = 4, then save. Auto Scaling launches another instance and registers it with the target group. Once the instance passes health checks, the ASG will show three healthy instances.
A screenshot of the AWS EC2 Auto Scaling groups console showing one auto scaling group (MyASG) with 3/3 healthy instances and desired capacity set to 3. The top bar shows controls like Launch configurations, Launch templates, Actions, and a "Create Auto Scaling group" button.
To scale in, set Desired and Min to a lower value (for example, Desired = 2). Auto Scaling will terminate instances until the group reaches the new target capacity—allow a few minutes for instance termination and health-check updates. That covers the essentials: create a launch template, build an Auto Scaling group, attach an ALB, verify traffic distribution, and manually scale the group.

Watch Video

Practice Lab