DEV Community

Cover image for Auto Scalling Groups
Clinton Ogechi
Clinton Ogechi

Posted on • Updated on

Auto Scalling Groups

Auto Scaling Groups automatically manage the number of EC2 instances in your application to maintain availability and ensure performance. Whether you’re dealing with variable traffic or need to ensure high availability, ASGs have got you covered.

Aim

To provide a comprehensive guide on how to effectively leverage Auto Scaling Groups (ASGs) in AWS to maintain the availability and performance of your applications.

Objective

  • Creating a launch template.
  • Configuring an Auto Scaling Group.
  • Setting up a target tracking scaling policy.
  • Monitoring the performance of EC2 instances under load.

Steps

1. Create a Launch Template

Navigate to EC2: Open the Amazon EC2 console.
Launch Templates: In the navigation pane, under Instances, choose Launch templates.
Create Launch Template: Click on "Create launch template".
Image description
Name and Description: Provide a name and description for your launch template.

  1. Image: Select the desired Amazon Machine Image (AMI).
  2. Instance Type: Choose the instance type that suits your application's requirements.
  3. Key Pair: Select an existing key pair or create a new one.
  4. Security Groups: Add or create security groups to control inbound and outbound traffic.
  5. Network Settings: Configure network interfaces, subnets, and other network-related settings.
  6. Storage: Configure root volume and additional EBS volumes as needed.
  7. Advanced Details: Customize additional settings like user data, IAM roles, and monitoring.
  8. Create Launch Template: Click "Create launch template".

Image description

2. Create an Auto Scaling Group

  1. Navigate to Auto Scaling: Open the Auto Scaling console.
  2. Create Auto Scaling Group: Click on "Create Auto Scaling group". Image description
  3. Basic Configuration: Auto Scaling group name: Provide a name for your Auto Scaling group. Launch template: Select the launch template you created in step 1. VPC: Choose the VPC where you want to launch instances. Availability Zones: Select the desired availability zones. Image description Image description
  4. Group Size: Desired capacity: Specify the initial number of instances. Minimum capacity: Set the minimum number of instances. Maximum capacity: Set the maximum number of instances.
  5. Scaling Policies: Configure scaling policies based on your application's requirements. This involves defining trigger conditions and scaling actions. Image description
  6. Tags: Add tags to your Auto Scaling group for organization and filtering.
  7. Create Auto Scaling Group: Click "Create Auto Scaling group". Image description

Based on the desired capacity, Auto Scalling group will spin up two ec2 instances.

Image description

3. Create a Target Tracking Scaling Policy

  1. Navigate to Automatic Scaling: Open the Auto Scaling Group and go to the "Automatic scaling" tab.
  2. Add Scaling Policy: Under the "Target tracking scaling policies" section, click on "Create policy."
  3. Select Policy Type: Choose "Target tracking scaling policy" as the policy type.
  4. Configure Policy: Policy Name: Enter a name for your scaling policy. Metric Type: Select a predefined metric like Average CPU Utilization or use a custom CloudWatch metric. Target Value: Input the desired target value (e.g., 50 for 50% CPU utilization). Instance Warm-Up Period: Specify the warm-up period for new instances.
  5. Create the Policy: Click "Create" to finalize and activate the scaling policy. Image description

4. Install the Stress Tool on Your EC2 Instance

  1. Connect via SSH: Use Amazon EC2 Instance Connect to connect to your EC2 instance.
  2. Install the Stress Tool:
  3. Run the Stress Command: Generate CPU load by running the following command.
sudo yum install -y stress
Enter fullscreen mode Exit fullscreen mode
stress --cpu 2 --timeout 300
Enter fullscreen mode Exit fullscreen mode

Image description

  • Monitor Auto Scaling Group: Click on your Auto Scaling Group to view its details, then go to the Activity tab to see scaling actions as new instances are added.

Image description

  • Monitor Instances: In the EC2 Dashboard, under the Instances tab, you should the third instance launching as the load increases.

Image description

Conclusion

Auto Scaling Groups (ASGs) in AWS automatically adjust the number of EC2 instances to match demand, ensuring high availability and performance without manual intervention. With health checks, load balancing, and customizable scaling policies, ASGs offer a flexible and efficient solution for managing cloud resources, making them vital for scalable and resilient cloud architectures.

Top comments (0)