Skip to main content

Amazon EC2 Auto Scaling Group Has Capacity Rebalancing Enabled

Overview

This check verifies that your EC2 Auto Scaling groups have Capacity Rebalancing enabled. Capacity Rebalancing is a feature that helps maintain availability for workloads running on Spot Instances by proactively replacing instances that are at risk of interruption.

When AWS detects that a Spot Instance is about to be interrupted, Capacity Rebalancing automatically launches a replacement instance before the at-risk instance is terminated. This gives your application time to gracefully transition workloads to the new instance.

Risk

Without Capacity Rebalancing enabled, Spot Instance interruptions can cause:

  • Reduced capacity - Instances are terminated before replacements are ready
  • Service timeouts and errors - The two-minute interruption notice is often not enough time to recover
  • 5xx error spikes - Load balancer targets disappear without warning
  • Request backlog growth - Processing queues build up during recovery
  • Cascading failures - One interruption triggers problems across dependent services

Capacity Rebalancing acts on early warning signals (rebalance recommendations) rather than waiting for the final two-minute termination notice, giving you more time to prepare.

Remediation Steps

Prerequisites

  • Access to the AWS Console with permissions to modify Auto Scaling groups
  • The Auto Scaling group should be using Spot Instances (Capacity Rebalancing is specifically designed for Spot workloads)

AWS Console Method

  1. Open the Amazon EC2 console
  2. In the left navigation, scroll down and click Auto Scaling Groups
  3. Select the Auto Scaling group you want to update
  4. Click the Details tab
  5. Scroll down to find Purchase options and instance types (or Allocation strategies depending on your ASG configuration)
  6. Click Edit
  7. Check the box for Capacity rebalancing
  8. Click Update

The change takes effect immediately for future rebalance recommendations.

AWS CLI (optional)

Use the following command to enable Capacity Rebalancing on an existing Auto Scaling group:

aws autoscaling update-auto-scaling-group \
--auto-scaling-group-name <your-asg-name> \
--capacity-rebalance \
--region us-east-1

Replace <your-asg-name> with the name of your Auto Scaling group.

To verify the change:

aws autoscaling describe-auto-scaling-groups \
--auto-scaling-group-names <your-asg-name> \
--query 'AutoScalingGroups[0].CapacityRebalance' \
--region us-east-1

This should return true.

CloudFormation (optional)

To enable Capacity Rebalancing in CloudFormation, set CapacityRebalance: true in your Auto Scaling group resource.

Here is a complete example that creates an ASG with Capacity Rebalancing and recommended Spot settings:

AWSTemplateFormatVersion: '2010-09-09'
Description: Auto Scaling Group with Capacity Rebalancing enabled

Parameters:
ASGName:
Type: String
Description: Name of the Auto Scaling Group
LaunchTemplateId:
Type: String
Description: ID of the Launch Template
LaunchTemplateVersion:
Type: String
Description: Version of the Launch Template
Default: '$Latest'
VPCSubnetIds:
Type: List<AWS::EC2::Subnet::Id>
Description: List of subnet IDs for the ASG

Resources:
AutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AutoScalingGroupName: !Ref ASGName
MinSize: '1'
MaxSize: '10'
DesiredCapacity: '2'
VPCZoneIdentifier: !Ref VPCSubnetIds
CapacityRebalance: true
MixedInstancesPolicy:
LaunchTemplate:
LaunchTemplateSpecification:
LaunchTemplateId: !Ref LaunchTemplateId
Version: !Ref LaunchTemplateVersion
InstancesDistribution:
OnDemandBaseCapacity: 0
OnDemandPercentageAboveBaseCapacity: 0
SpotAllocationStrategy: price-capacity-optimized

Outputs:
AutoScalingGroupName:
Description: Name of the Auto Scaling Group
Value: !Ref AutoScalingGroup

Key properties:

  • CapacityRebalance: true - Enables the Capacity Rebalancing feature
  • SpotAllocationStrategy: price-capacity-optimized - Recommended strategy that balances cost savings with availability
Terraform (optional)

To enable Capacity Rebalancing in Terraform, set capacity_rebalance = true in your aws_autoscaling_group resource.

Here is a complete example:

resource "aws_autoscaling_group" "main" {
name = var.asg_name
min_size = 1
max_size = 10
desired_capacity = 2
vpc_zone_identifier = var.vpc_subnet_ids
capacity_rebalance = true

mixed_instances_policy {
instances_distribution {
on_demand_base_capacity = 0
on_demand_percentage_above_base_capacity = 0
spot_allocation_strategy = "price-capacity-optimized"
}

launch_template {
launch_template_specification {
launch_template_id = var.launch_template_id
version = var.launch_template_version
}
}
}

tag {
key = "Name"
value = var.asg_name
propagate_at_launch = true
}
}

Key attributes:

  • capacity_rebalance = true - Enables the Capacity Rebalancing feature
  • spot_allocation_strategy = "price-capacity-optimized" - Recommended strategy for balancing cost and availability

Verification

After enabling Capacity Rebalancing, verify the configuration:

  1. In the AWS Console, go to EC2 > Auto Scaling Groups
  2. Select your Auto Scaling group
  3. Check the Details tab
  4. Look for Capacity rebalancing - it should show Enabled
CLI verification
aws autoscaling describe-auto-scaling-groups \
--auto-scaling-group-names <your-asg-name> \
--query 'AutoScalingGroups[0].{Name:AutoScalingGroupName,CapacityRebalance:CapacityRebalance}' \
--output table \
--region us-east-1

Expected output:

-------------------------------------------
| DescribeAutoScalingGroups |
+-------------------+---------------------+
| CapacityRebalance | Name |
+-------------------+---------------------+
| True | your-asg-name |
+-------------------+---------------------+

Additional Resources

Notes

  • Spot-only benefit: Capacity Rebalancing is designed for Spot Instances. If your ASG only uses On-Demand instances, this feature has no effect.

  • Maintain headroom: Keep your DesiredCapacity below MaxSize so the ASG can launch replacement instances before terminating at-risk ones. If you are at max capacity, there is no room to launch replacements proactively.

  • Use lifecycle hooks: For graceful handling, configure lifecycle hooks to drain connections and deregister from load balancers before instances terminate.

  • Design for interruption: Capacity Rebalancing works best with stateless, interruption-tolerant workloads. Store state externally and design your application to handle instance replacement gracefully.

  • Allocation strategy: Use price-capacity-optimized as your Spot allocation strategy for the best balance of cost savings and availability.

  • No additional cost: Capacity Rebalancing itself is free. You only pay for the instances launched.