Swiftorial Logo
Home
Swift Lessons
Tutorials
Learn More
Career
Resources

AWS Auto Scaling Basics

What is Auto Scaling?

Amazon EC2 Auto Scaling helps you maintain application availability and allows you to automatically add or remove EC2 instances according to conditions you define. You can use the fleet management features to maintain the health and availability of your fleet. You can also use the dynamic and predictive scaling features to add or remove EC2 instances.

Key Auto Scaling Concepts

  • Auto Scaling Group: A collection of EC2 instances that you manage as a single unit. You can specify the minimum, maximum, and desired number of instances in the group.
  • Launch Configuration: An instance configuration template that an Auto Scaling group uses to launch EC2 instances.
  • Scaling Policies: Define the conditions under which your Auto Scaling group should increase or decrease the number of instances.
  • Scheduled Actions: Add or remove instances at specific times, based on a schedule.

Creating an Auto Scaling Group

To create an Auto Scaling group:

  1. Sign in to the AWS Management Console.
  2. Navigate to the EC2 Dashboard.
  3. In the left navigation pane, click "Auto Scaling Groups" and then click "Create Auto Scaling group".
  4. Configure the Auto Scaling group settings:
    • Group name: Enter a name for your Auto Scaling group.
    • Launch template: Choose an existing launch template or create a new one. A launch template specifies the instance configuration.
    • Fleet details: Specify the number of instances to start with (desired capacity), as well as the minimum and maximum number of instances.
    • Network: Choose the VPC and subnets where the instances will be launched.
  5. Click "Next" to configure advanced options, such as health checks and instance scale-in protection.
  6. Click "Next" to configure notifications and CloudWatch alarms.
  7. Click "Next" to add tags to your Auto Scaling group.
  8. Click "Create Auto Scaling group" to save your settings.

Creating a Launch Configuration

To create a launch configuration:

  1. Sign in to the AWS Management Console.
  2. Navigate to the EC2 Dashboard.
  3. In the left navigation pane, click "Launch Configurations" and then click "Create launch configuration".
  4. Configure the launch configuration settings:
    • Launch configuration name: Enter a name for your launch configuration.
    • AMI ID: Choose an Amazon Machine Image (AMI) to use.
    • Instance type: Choose an instance type (e.g., t2.micro).
    • Key pair: Select an existing key pair or create a new one to access your instances.
    • Security groups: Select one or more security groups to associate with the instances.
    • Storage: Configure the root volume and additional storage volumes.
  5. Click "Create launch configuration" to save your settings.

Example: Creating an Auto Scaling Group with a Launch Configuration

Let's create an Auto Scaling group with a launch configuration:

Step-by-Step Example:

  1. Sign in to the AWS Management Console.
  2. Navigate to the EC2 Dashboard and click "Launch Configurations" in the left navigation pane.
  3. Click "Create launch configuration".
  4. Configure the launch configuration settings:
    • Launch configuration name: Enter "MyLaunchConfig".
    • AMI ID: Choose an Amazon Linux 2 AMI.
    • Instance type: Choose t2.micro.
    • Key pair: Select an existing key pair or create a new one.
    • Security groups: Select a security group that allows HTTP and SSH traffic.
  5. Click "Create launch configuration" to save your settings.
  6. Navigate to "Auto Scaling Groups" and click "Create Auto Scaling group".
  7. Configure the Auto Scaling group settings:
    • Group name: Enter "MyAutoScalingGroup".
    • Launch template: Select "MyLaunchConfig".
    • Fleet details: Set the desired capacity to 2, minimum capacity to 1, and maximum capacity to 4.
    • Network: Select your VPC and subnets.
  8. Click "Next" to configure advanced options, such as health checks and instance scale-in protection.
  9. Click "Next" to configure notifications and CloudWatch alarms.
  10. Click "Next" to add tags to your Auto Scaling group.
  11. Click "Create Auto Scaling group" to finalize the setup.

Configuring Scaling Policies

To configure scaling policies for your Auto Scaling group:

  1. Sign in to the AWS Management Console.
  2. Navigate to the EC2 Dashboard.
  3. In the left navigation pane, click "Auto Scaling Groups".
  4. Select the Auto Scaling group you want to modify and click "Edit".
  5. Navigate to the "Scaling Policies" section.
  6. Click "Add policy" to create a new scaling policy.
  7. Choose the policy type:
    • Target Tracking: Adjusts the number of instances to maintain a target metric (e.g., average CPU utilization).
    • Step Scaling: Adjusts the number of instances based on a set of scaling adjustments (e.g., add 1 instance if CPU > 70%).
    • Simple Scaling: Adjusts the number of instances based on a single scaling adjustment.
  8. Configure the policy settings and click "Create" to save the policy.

Example: Creating a Target Tracking Scaling Policy

Let's create a target tracking scaling policy to maintain average CPU utilization:

Step-by-Step Example:

  1. Sign in to the AWS Management Console.
  2. Navigate to the EC2 Dashboard and click "Auto Scaling Groups" in the left navigation pane.
  3. Select "MyAutoScalingGroup" and click "Edit".
  4. Navigate to the "Scaling Policies" section and click "Add policy".
  5. Choose "Target Tracking" as the policy type.
  6. Configure the policy settings:
    • Policy name: Enter "MaintainCPUUtilization".
    • Target value: Enter 50 (for 50% average CPU utilization).
    • Instances: Select the appropriate instances to apply the policy to.
  7. Click "Create" to save the policy.

Monitoring and Managing Auto Scaling Groups

You can monitor and manage your Auto Scaling groups using the AWS Management Console, AWS CLI, or CloudWatch:

  • Monitor Auto Scaling Metrics: Use CloudWatch to monitor metrics such as group desired capacity, group in-service instances, and group pending instances.
  • View Scaling Activities: Check the Auto Scaling group's activity history to see scaling events and the status of instances.
  • Manage Instances: Manually add or remove instances, or update the desired capacity of the group.
  • Update Scaling Policies: Modify existing scaling policies or create new ones to adjust scaling behavior.

Example: Viewing Auto Scaling Group Metrics

Let's view metrics for an Auto Scaling group:

Step-by-Step Example:

  1. Sign in to the AWS Management Console.
  2. Navigate to the CloudWatch Dashboard.
  3. In the left navigation pane, click "Metrics".
  4. Choose "Auto Scaling" from the list of available metrics.
  5. Select the Auto Scaling group and metric you want to view, such as "GroupDesiredCapacity" or "GroupInServiceInstances".
  6. Use the available tools to customize the metric graph, set alarms, and analyze performance trends.

Conclusion

Amazon EC2 Auto Scaling helps you maintain application availability and scale your EC2 instances automatically according to your defined conditions. By understanding the basics of Auto Scaling, including how to create Auto Scaling groups, launch configurations, and scaling policies, you can ensure that your applications remain highly available and responsive to changes in demand.