Auto Scaling Groups

Auto Scaling Groups

Table of contents

Introduction

Auto Scaling Groups (ASGs) are a key feature in Amazon Web Services (AWS) that enable automatic scaling of EC2 instances based on user-defined policies. An Auto Scaling Group maintains a specified number of EC2 instances across multiple Availability Zones, automatically adjusting the capacity to handle changes in demand for your application.

Key features and concepts associated with Auto Scaling Groups include:

  1. Launch Configurations or Launch Templates:

    • ASGs use either launch configurations (for older accounts) or launch templates (for more recent accounts) to define the configuration parameters for the EC2 instances that will be launched. These parameters include the Amazon Machine Image (AMI), instance type, key pair, security groups, and user data.
  2. Desired Capacity:

    • The desired capacity is the number of EC2 instances that the Auto Scaling Group is configured to maintain at any given time. It represents the target number of instances.
  3. Minimum and Maximum Capacity:

    • ASGs allow you to set minimum and maximum capacity limits, defining the range within which the number of instances can automatically scale. Instances are added or removed based on demand within these capacity limits.
  4. Scaling Policies:

    • Scaling policies define the conditions under which the Auto Scaling Group should automatically scale. There are two types of scaling policies:

      • Scale-Out Policy: Adds instances when certain conditions are met (e.g., CPU utilization exceeds a threshold).

      • Scale-In Policy: Removes instances when certain conditions are met (e.g., CPU utilization falls below a threshold).

  5. Cooldown Period:

    • The cooldown period is the time interval during which the Auto Scaling Group does not launch or terminate additional instances after a scaling activity. This helps prevent the group from launching or terminating instances before the previous ones have fully come into service.
  6. Health Checks:

    • ASGs perform health checks on instances to determine their status. If an instance fails a health check, the ASG can terminate it and replace it with a healthy instance.
  7. Lifecycle Hooks:

    • Lifecycle hooks provide a way to perform custom actions before instances are launched or terminated. This can be useful for tasks such as setting up or tearing down resources associated with instances.
  8. Integration with Other AWS Services:

    • ASGs seamlessly integrate with other AWS services, such as Elastic Load Balancing (ELB) and AWS CloudWatch for monitoring and health checks.
  9. Instance Termination Policies:

    • Instance termination policies determine which instances are selected for termination when scaling in. Common termination policies include OldestInstance and Default.
  10. Mixed Instances Policies (Optional):

    • ASGs support mixed instances policies, allowing you to use a combination of instance types and purchase options (e.g., On-Demand and Spot Instances) within the same Auto Scaling Group.