当Auto Scaling组的实例在线容量低于所需容量时,可以通过以下代码示例来扩大组的容量:
import boto3
asg_name = 'your-asg-name'
asg_client = boto3.client('autoscaling')
response = asg_client.describe_auto_scaling_groups( AutoScalingGroupNames=[ asg_name ] )
desired_capacity = response['AutoScalingGroups'][0]['DesiredCapacity']
online_instances = len(response['AutoScalingGroups'][0]['Instances'])
if online_instances < desired_capacity: asg_client.set_desired_capacity( AutoScalingGroupName=asg_name, DesiredCapacity=desired_capacity )