> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Autoscaling From Idea to Scale in EC2

> Step by step guide to autoscale EC2 web servers using Launch Templates, an Auto Scaling Group and an Application Load Balancer with health checks, testing and cleanup instructions

This walkthrough demonstrates how to autoscale web servers on Amazon EC2 using a Launch Template, an Auto Scaling Group (ASG), and an Application Load Balancer (ALB). Follow the steps in order — the screenshots are placed beside the steps they illustrate.

First, open the EC2 service in the AWS Console and navigate to Launch Templates.

![A screenshot of the Amazon Web Services EC2 dashboard in the US (Ohio) region, showing a Resources summary panel. The panel lists counts for items like Instances (2), Security groups (2), and other EC2 resources.](https://mintcdn.com/kodekloud-c4ac6d9a/x-CkTJgJqym_5mBk/images/AWS-Certified-DevOps-Engineer-Professional/Domain-3-Resilient-Cloud-Solutions/Demo-Autoscaling-From-Idea-to-Scale-in-EC2/aws-ec2-ohio-resources-summary.jpg?fit=max\&auto=format\&n=x-CkTJgJqym_5mBk\&q=85\&s=f14b88c8827e052bbbee035b4da6e321)

## What you'll create

* A Launch Template that defines the instance configuration and user data.
* An Auto Scaling Group that manages EC2 capacity.
* An Application Load Balancer that distributes HTTP traffic and provides health checks.

Useful references:

* [EC2 Launch Templates](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html)
* [Auto Scaling Groups](https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html)
* [Application Load Balancers](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html)

## Create a Launch Template

A launch template is a reusable blueprint for instances launched by Auto Scaling. It captures AMI, instance type, security groups, key pair, and user data that run at boot.

Click **Create launch template** and fill out the core fields.

![A screenshot of the AWS EC2 console on the "Create launch template" page, showing the "Launch template name" field filled with "MyTemplate" and a "Template version description" field below. The browser UI and AWS navigation/header are visible at the top.](https://mintcdn.com/kodekloud-c4ac6d9a/x-CkTJgJqym_5mBk/images/AWS-Certified-DevOps-Engineer-Professional/Domain-3-Resilient-Cloud-Solutions/Demo-Autoscaling-From-Idea-to-Scale-in-EC2/aws-ec2-create-launch-template-screenshot.jpg?fit=max\&auto=format\&n=x-CkTJgJqym_5mBk\&q=85\&s=4bcc777003e28e14f4bc5e79ebab5df6)

Key settings to configure:

* Launch template name and optional description (example: `MyTemplate`).
* AMI: choose an image (this example uses Amazon Linux from Quick Start).
* Instance type: `t3.micro` is a good small-test choice; `t2.micro` may be included in the Free Tier.
* Key pair: optional for this demo — you can leave blank if you don't need SSH access.
* Security group: create or select one that allows HTTP (port 80). Example security group rules:
  * Type: HTTP
  * Protocol: TCP
  * Port: 80
  * Source: `0.0.0.0/0`

Scroll to Advanced Details and paste the following user data. This script installs Apache (httpd), enables and starts it, and writes a simple index page that includes the instance hostname — useful for verifying load balancing.

```bash theme={null}
#!/bin/bash
# User data: install and start httpd on Amazon Linux variants (compatible with Amazon Linux 2 and 2023)
if command -v dnf >/dev/null 2>&1; then
  dnf update -y
  dnf install -y httpd
else
  yum update -y
  yum install -y httpd
fi
systemctl start httpd
systemctl enable httpd
echo "<h1> Hi from $(hostname -f)</h1>" > /var/www/html/index.html
```

When finished, create the launch template.

![A screenshot of the AWS EC2 console on the "Create launch template" Summary page showing the selected AMI (Amazon Linux 2023), instance type t3.micro, and a new security group. An orange "Create launch template" button is visible at the bottom right.](https://mintcdn.com/kodekloud-c4ac6d9a/x-CkTJgJqym_5mBk/images/AWS-Certified-DevOps-Engineer-Professional/Domain-3-Resilient-Cloud-Solutions/Demo-Autoscaling-From-Idea-to-Scale-in-EC2/aws-ec2-launch-template-ami-t3micro.jpg?fit=max\&auto=format\&n=x-CkTJgJqym_5mBk\&q=85\&s=baf39ab86a2704b4fe8abe543f3ed2d4)

The user data will run automatically when each instance boots, and the index page helps identify which instance served a request.

![A screenshot of the AWS EC2 console creating a launch template, showing a blue progress bar at 75%. The page displays the message "Please wait while we create your template — do not close your browser while this is loading."](https://mintcdn.com/kodekloud-c4ac6d9a/x-CkTJgJqym_5mBk/images/AWS-Certified-DevOps-Engineer-Professional/Domain-3-Resilient-Cloud-Solutions/Demo-Autoscaling-From-Idea-to-Scale-in-EC2/aws-ec2-launch-template-progress-75.jpg?fit=max\&auto=format\&n=x-CkTJgJqym_5mBk\&q=85\&s=c211a82051dcd46b3ab3518eb4aa048d)

Once the template is created, go back to the EC2 panel and open **Auto Scaling Groups**.

## Create an Auto Scaling Group

Start **Create Auto Scaling group** and configure the basics:

* Name the group (example: `MyASG`).
* Select the launch template you created (`MyTemplate`) and the appropriate version.

![A screenshot of the AWS EC2 console on the "Create Auto Scaling group" page showing the Launch template section with "MyTemplate" selected. The left sidebar shows setup steps and the browser toolbar is visible at the top.](https://mintcdn.com/kodekloud-c4ac6d9a/x-CkTJgJqym_5mBk/images/AWS-Certified-DevOps-Engineer-Professional/Domain-3-Resilient-Cloud-Solutions/Demo-Autoscaling-From-Idea-to-Scale-in-EC2/aws-ec2-autoscaling-launch-template-screenshot.jpg?fit=max\&auto=format\&n=x-CkTJgJqym_5mBk\&q=85\&s=5711a25469ae811b1e66182f35644b89)

Network and Availability Zone settings:

* Choose your VPC and select multiple subnets across AZs for high availability (in this demo: `2a`, `2b`, `2c`).
* Keep Availability Zone distribution at the default Balanced (best effort).

![A screenshot of the AWS EC2 console on the "Create Auto Scaling group" page showing Availability Zone distribution options, with "Balanced best effort" selected.](https://mintcdn.com/kodekloud-c4ac6d9a/x-CkTJgJqym_5mBk/images/AWS-Certified-DevOps-Engineer-Professional/Domain-3-Resilient-Cloud-Solutions/Demo-Autoscaling-From-Idea-to-Scale-in-EC2/aws-ec2-auto-scaling-balanced-az.jpg?fit=max\&auto=format\&n=x-CkTJgJqym_5mBk\&q=85\&s=8d1f62d2fe10b3c5edbdf65567b5cd84)

![A screenshot of the AWS EC2 console on the "Create Auto Scaling group" page, showing the Network section with options for VPC, availability zones, and subnets. The VPC dropdown (172.31.0.0/16) and related configuration controls are visible.](https://mintcdn.com/kodekloud-c4ac6d9a/x-CkTJgJqym_5mBk/images/AWS-Certified-DevOps-Engineer-Professional/Domain-3-Resilient-Cloud-Solutions/Demo-Autoscaling-From-Idea-to-Scale-in-EC2/aws-ec2-auto-scaling-network-vpc.jpg?fit=max\&auto=format\&n=x-CkTJgJqym_5mBk\&q=85\&s=f14101c7ba6ad3edf76e74bfba753f6b)

### Attach an Application Load Balancer

Attach an ALB to distribute traffic and provide health checks for the ASG:

* Choose to attach a new load balancer and select **Application Load Balancer**.
* Name the load balancer (example: `MyLB`) and create a target group (example: `MyTargetGroup`) that will register instances.
* Configure an HTTP listener on port 80 and forward traffic to the target group.

![A screenshot of the AWS EC2 console on the "Create Auto Scaling group" page showing listener and routing settings. It shows an HTTP listener on port 80 and a new target group named "MyTargetGroup" being created.](https://mintcdn.com/kodekloud-c4ac6d9a/x-CkTJgJqym_5mBk/images/AWS-Certified-DevOps-Engineer-Professional/Domain-3-Resilient-Cloud-Solutions/Demo-Autoscaling-From-Idea-to-Scale-in-EC2/aws-ec2-autoscaling-http-listener-80.jpg?fit=max\&auto=format\&n=x-CkTJgJqym_5mBk\&q=85\&s=7a3001cdd6f6b25d8af5c580ffe4f56e)

Enable ELB health checks so the load balancer reports instance health to Auto Scaling; ASG can replace instances that fail health checks.

![A screenshot of the AWS EC2 "Create Auto Scaling group" page showing health-check options. The "Turn on Elastic Load Balancing health checks" box is checked and a blue info notice explains how Auto Scaling uses load balancer health checks.](https://mintcdn.com/kodekloud-c4ac6d9a/x-CkTJgJqym_5mBk/images/AWS-Certified-DevOps-Engineer-Professional/Domain-3-Resilient-Cloud-Solutions/Demo-Autoscaling-From-Idea-to-Scale-in-EC2/aws-auto-scaling-elb-health-checks.jpg?fit=max\&auto=format\&n=x-CkTJgJqym_5mBk\&q=85\&s=f1c70e0c0b35a11fda35ecba2d852deb)

Set group size values:

* Minimum capacity: minimum number of instances to keep running.
* Desired capacity: target number of instances Auto Scaling aims to maintain.
* Maximum capacity: hard upper limit for scaling out.

Example (demo):

* Min = 2, Desired = 2, Max = 3

When ready, create the Auto Scaling Group — it will provision instances and the ALB.

## Wait for Load Balancer Provisioning

Creating an Application Load Balancer can take several minutes (commonly 5–10). Refresh the Load Balancers view after a short wait.

ALBs may take a few minutes to show as Active. While waiting, you can monitor provisioning progress in the Load Balancers console or continue configuring other resources.

After provisioning, the ALB should be in the Active state and provide a DNS name you can use to test.

![A screenshot of the AWS EC2 "Load balancers" console. It shows one load balancer named "MyLB" in Active state (application type, Internet-facing, IPv4) with a "Create load balancer" button.](https://mintcdn.com/kodekloud-c4ac6d9a/x-CkTJgJqym_5mBk/images/AWS-Certified-DevOps-Engineer-Professional/Domain-3-Resilient-Cloud-Solutions/Demo-Autoscaling-From-Idea-to-Scale-in-EC2/aws-ec2-load-balancer-mylb-active.jpg?fit=max\&auto=format\&n=x-CkTJgJqym_5mBk\&q=85\&s=851e08eae5465384c0d000bcf79ed27e)

To test, open a browser and enter the ALB DNS using `http://` followed by the DNS name, for example:

`http://mylb-404326469.us-east-2.elb.amazonaws.com`

The page should show the index content created by the user data script, which identifies the instance:

```text theme={null}
Hi from ip-172-31-9-51.us-east-2.compute.internal
```

Refreshing the page repeatedly should show different hostnames as the ALB distributes requests across the ASG instances.

You can inspect the ALB resource map to view listeners, rules, and target group registrations. The target group shows registered instances and health status. In this demo both instances are healthy and registered on port 80.

![A screenshot of the AWS EC2 console showing the Load Balancers page for a load balancer named "MyLB," with a target group and two EC2 targets shown as healthy on port 80.](https://mintcdn.com/kodekloud-c4ac6d9a/x-CkTJgJqym_5mBk/images/AWS-Certified-DevOps-Engineer-Professional/Domain-3-Resilient-Cloud-Solutions/Demo-Autoscaling-From-Idea-to-Scale-in-EC2/aws-ec2-mylb-targets-healthy-port80.jpg?fit=max\&auto=format\&n=x-CkTJgJqym_5mBk\&q=85\&s=7642f5fb9a2e6e5f20799e51d6d278ac)

## Clean up resources to avoid charges

To avoid ongoing charges, delete the resources you created:

* Auto Scaling Group: select the group → Actions → Delete.
* Load Balancer: select the ALB → Actions → Delete.
* (Optional) Delete the launch template and any security groups created for the demo.

Always terminate demo resources when finished. Leaving ALBs and running instances can incur charges even if usage is light.

![Screenshot of the AWS EC2 console Auto Scaling groups page. It shows one group named "MyASG" selected with status "At desired capacity" and buttons for launch configurations, templates, Actions, and "Create Auto Scaling group."](https://mintcdn.com/kodekloud-c4ac6d9a/x-CkTJgJqym_5mBk/images/AWS-Certified-DevOps-Engineer-Professional/Domain-3-Resilient-Cloud-Solutions/Demo-Autoscaling-From-Idea-to-Scale-in-EC2/aws-ec2-auto-scaling-myasg-console.jpg?fit=max\&auto=format\&n=x-CkTJgJqym_5mBk\&q=85\&s=c7de2129dbb9c180b014bad258249ecc)

## Manually scaling in and out

Auto Scaling supports manual capacity changes and policy-driven automatic scaling (CloudWatch alarms, target tracking, scheduled actions).

Two quick ways to edit capacity:

* Select the scaling group → Actions → Edit → update Desired/Min/Max → Save.
* Open the group's Details panel and click **Edit** there.

The console shows the ASG ARN for reference. Example:

```text theme={null}
arn:aws:autoscaling:us-east-2:635573991785:autoScalingGroup:a57b627a-beb5-4293-8dc7-60acfc9e8e81:autoScalingGroupName/MyASG
```

Example manual workflows:

* Scale out: set Desired = 3 and Max = 4 → Update. The ASG launches instances to reach Desired.
* Scale in: reduce Desired (and optionally Min) → Update. The ASG terminates instances to match the new target.

Changes can take a few minutes; refresh the Auto Scaling group details to confirm instance counts and health.

![A screenshot of the AWS EC2 Auto Scaling groups edit page showing Desired capacity set to 2 and Scaling limits with Min desired capacity = 2 and Max desired capacity = 3. The AWS console header and part of the Launch template section are also visible.](https://mintcdn.com/kodekloud-c4ac6d9a/x-CkTJgJqym_5mBk/images/AWS-Certified-DevOps-Engineer-Professional/Domain-3-Resilient-Cloud-Solutions/Demo-Autoscaling-From-Idea-to-Scale-in-EC2/aws-ec2-autoscaling-desired2-min2-max3.jpg?fit=max\&auto=format\&n=x-CkTJgJqym_5mBk\&q=85\&s=9e3aeab580438cba282226883b65dc2e)

Use scaling policies (CPU utilization, request count, scheduled actions, or CloudWatch alarms) to automate scaling decisions in production environments.

## Quick settings reference

| Resource | Purpose | Example values |
| - | - | - |
| Launch Template | Defines AMI, instance type, security groups, user data | `MyTemplate`, AMI = Amazon Linux, type = `t3.micro` |
| Auto Scaling Group | Manages instance fleet size and distribution | `MyASG`, Min=2, Desired=2, Max=3 |
| Application Load Balancer | Distributes HTTP traffic and performs health checks | `MyLB`, Listener = HTTP:80, Target group = `MyTargetGroup` |

That completes the flow: create a launch template with user data, create an Auto Scaling Group attached to an Application Load Balancer, verify traffic distribution via the ALB DNS, and manually scale the group as needed.

> **[Watch Video](https://learn.kodekloud.com/user/courses/aws-certified-devops-engineer-professional/module/614fb8a5-8397-4ea6-9d7c-fe05ebc43d18/lesson/ab5705b1-55eb-4b7e-ac2b-70ff48e32dae)**

> **[Practice Lab](https://learn.kodekloud.com/user/courses/aws-certified-devops-engineer-professional/module/614fb8a5-8397-4ea6-9d7c-fe05ebc43d18/lesson/f0f27abd-8a25-41a0-9f3e-8d7d00c39140)**


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.