update_auto_scaling_group
¶
update_auto_scaling_group(
*,
config_overrides: Optional[AutoScalingClientConfig] = None,
auto_scaling_group_name: Optional[XmlStringMaxLen255] = None,
launch_configuration_name: Optional[XmlStringMaxLen255] = None,
launch_template: Optional[LaunchTemplateSpecification] = None,
mixed_instances_policy: Optional[MixedInstancesPolicy] = None,
min_size: Optional[AutoScalingGroupMinSize] = None,
max_size: Optional[AutoScalingGroupMaxSize] = None,
desired_capacity: Optional[AutoScalingGroupDesiredCapacity] = None,
default_cooldown: Optional[Cooldown] = None,
availability_zones: Optional[AvailabilityZones] = None,
availability_zone_ids: Optional[AvailabilityZoneIds] = None,
health_check_type: Optional[XmlStringMaxLen32] = None,
health_check_grace_period: Optional[HealthCheckGracePeriod] = None,
placement_group: Optional[UpdatePlacementGroupParam] = None,
vpc_zone_identifier: Optional[XmlStringMaxLen5000] = None,
termination_policies: Optional[TerminationPolicies] = None,
new_instances_protected_from_scale_in: Optional[InstanceProtected] = None,
service_linked_role_arn: Optional[ResourceName] = None,
max_instance_lifetime: Optional[MaxInstanceLifetime] = None,
capacity_rebalance: Optional[CapacityRebalanceEnabled] = None,
context: Optional[Context] = None,
desired_capacity_type: Optional[XmlStringMaxLen255] = None,
default_instance_warmup: Optional[DefaultInstanceWarmup] = None,
instance_maintenance_policy: Optional[InstanceMaintenancePolicy] = None,
availability_zone_distribution: Optional[AvailabilityZoneDistribution] = None,
availability_zone_impairment_policy: Optional[
AvailabilityZoneImpairmentPolicy
] = None,
skip_zonal_shift_validation: Optional[SkipZonalShiftValidation] = None,
capacity_reservation_specification: Optional[
CapacityReservationSpecification
] = None,
instance_lifecycle_policy: Optional[InstanceLifecyclePolicy] = None,
deletion_protection: Optional[DeletionProtection] = None,
) -> None
We strongly recommend that all Auto Scaling groups use launch templates to ensure full functionality for Amazon EC2 Auto Scaling and Amazon EC2.
Updates the configuration for the specified Auto Scaling group.
To update an Auto Scaling group, specify the name of the group and the property that you want to change. Any properties that you don't specify are not changed by this update request. The new settings take effect on any scaling activities after this call returns.
If you associate a new launch configuration or template with an Auto Scaling group, all new instances will get the updated configuration. Existing instances continue to run with the configuration that they were originally launched with. When you update a group to specify a mixed instances policy instead of a launch configuration or template, existing instances may be replaced to match the new purchasing options that you specified in the policy. For example, if the group currently has 100% On-Demand capacity and the policy specifies 50% Spot capacity, this means that half of your instances will be gradually terminated and relaunched as Spot Instances. When replacing instances, Amazon EC2 Auto Scaling launches new instances before terminating the old ones, so that updating your group does not compromise the performance or availability of your application.
Note the following about changing DesiredCapacity, MaxSize, or MinSize:
-
If a scale-in activity occurs as a result of a new
DesiredCapacityvalue that is lower than the current size of the group, the Auto Scaling group uses its termination policy to determine which instances to terminate. -
If you specify a new value for
MinSizewithout specifying a value forDesiredCapacity, and the newMinSizeis larger than the current size of the group, this sets the group'sDesiredCapacityto the newMinSizevalue. -
If you specify a new value for
MaxSizewithout specifying a value forDesiredCapacity, and the newMaxSizeis smaller than the current size of the group, this sets the group'sDesiredCapacityto the newMaxSizevalue.
To see which properties have been set, call the DescribeAutoScalingGroups API. To view the scaling policies for an Auto Scaling group, call the DescribePolicies API. If the group has scaling policies, you can update them by calling the PutScalingPolicy API.
Parameters:
-
auto_scaling_group_name(Optional[XmlStringMaxLen255], default:None) –The name of the Auto Scaling group.
-
launch_configuration_name(Optional[XmlStringMaxLen255], default:None) –The name of the launch configuration. If you specify
LaunchConfigurationNamein your update request, you can't specifyLaunchTemplateorMixedInstancesPolicy. -
launch_template(Optional[LaunchTemplateSpecification], default:None) –The launch template and version to use to specify the updates. If you specify
LaunchTemplatein your update request, you can't specifyLaunchConfigurationNameorMixedInstancesPolicy. -
mixed_instances_policy(Optional[MixedInstancesPolicy], default:None) –The mixed instances policy. For more information, see Auto Scaling groups with multiple instance types and purchase options in the Amazon EC2 Auto Scaling User Guide.
You can remove the Distribution Segments configuration by specifying
OnDemandBaseCapacityorOnDemandPercentageAboveBaseCapacity. You can also remove it explicitly by specifying an empty list forDistributionSegments. -
min_size(Optional[AutoScalingGroupMinSize], default:None) –The minimum size of the Auto Scaling group.
-
max_size(Optional[AutoScalingGroupMaxSize], default:None) –The maximum size of the Auto Scaling group.
With a mixed instances policy that uses instance weighting, Amazon EC2 Auto Scaling may need to go above
MaxSizeto meet your capacity requirements. In this event, Amazon EC2 Auto Scaling will never go aboveMaxSizeby more than your largest instance weight (weights that define how many units each instance contributes to the desired capacity of the group). -
desired_capacity(Optional[AutoScalingGroupDesiredCapacity], default:None) –The desired capacity is the initial capacity of the Auto Scaling group after this operation completes and the capacity it attempts to maintain. This number must be greater than or equal to the minimum size of the group and less than or equal to the maximum size of the group.
-
default_cooldown(Optional[Cooldown], default:None) –Only needed if you use simple scaling policies.
The amount of time, in seconds, between one scaling activity ending and another one starting due to simple scaling policies. For more information, see Scaling cooldowns for Amazon EC2 Auto Scaling in the Amazon EC2 Auto Scaling User Guide.
-
availability_zones(Optional[AvailabilityZones], default:None) –One or more Availability Zones for the group.
-
availability_zone_ids(Optional[AvailabilityZoneIds], default:None) –A list of Availability Zone IDs for the Auto Scaling group. You cannot specify both AvailabilityZones and AvailabilityZoneIds in the same request.
-
health_check_type(Optional[XmlStringMaxLen32], default:None) –A comma-separated value string of one or more health check types.
The valid values are
EC2,EBS,ELB, andVPC_LATTICE.EC2is the default health check and cannot be disabled. For more information, see Health checks for instances in an Auto Scaling group in the Amazon EC2 Auto Scaling User Guide.Only specify
EC2if you must clear a value that was previously set. -
health_check_grace_period(Optional[HealthCheckGracePeriod], default:None) –The amount of time, in seconds, that Amazon EC2 Auto Scaling waits before checking the health status of an EC2 instance that has come into service and marking it unhealthy due to a failed health check. This is useful if your instances do not immediately pass their health checks after they enter the
InServicestate. For more information, see Set the health check grace period for an Auto Scaling group in the Amazon EC2 Auto Scaling User Guide. -
placement_group(Optional[UpdatePlacementGroupParam], default:None) –The name of an existing placement group into which to launch your instances. To remove the placement group setting, pass an empty string for
placement-group. For more information about placement groups, see Placement groups in the Amazon EC2 User Guide.A cluster placement group is a logical grouping of instances within a single Availability Zone. You cannot specify multiple Availability Zones and a cluster placement group.
-
vpc_zone_identifier(Optional[XmlStringMaxLen5000], default:None) –A comma-separated list of subnet IDs for a virtual private cloud (VPC). If you specify
VPCZoneIdentifierwithAvailabilityZones, the subnets that you specify must reside in those Availability Zones. -
termination_policies(Optional[TerminationPolicies], default:None) –A policy or a list of policies that are used to select the instances to terminate. The policies are executed in the order that you list them. For more information, see Configure termination policies for Amazon EC2 Auto Scaling in the Amazon EC2 Auto Scaling User Guide.
Valid values:
Default|AllocationStrategy|ClosestToNextInstanceHour|NewestInstance|OldestInstance|OldestLaunchConfiguration|OldestLaunchTemplate|arn:aws:lambda:region:account-id:function:my-function:my-alias -
new_instances_protected_from_scale_in(Optional[InstanceProtected], default:None) –Indicates whether newly launched instances are protected from termination by Amazon EC2 Auto Scaling when scaling in. For more information about preventing instances from terminating on scale in, see Use instance scale-in protection in the Amazon EC2 Auto Scaling User Guide.
-
service_linked_role_arn(Optional[ResourceName], default:None) –The Amazon Resource Name (ARN) of the service-linked role that the Auto Scaling group uses to call other Amazon Web Services on your behalf. For more information, see Service-linked roles in the Amazon EC2 Auto Scaling User Guide.
-
max_instance_lifetime(Optional[MaxInstanceLifetime], default:None) –The maximum amount of time, in seconds, that an instance can be in service. The default is null. If specified, the value must be either 0 or a number equal to or greater than 86,400 seconds (1 day). To clear a previously set value, specify a new value of 0. For more information, see Replacing Auto Scaling instances based on maximum instance lifetime in the Amazon EC2 Auto Scaling User Guide.
-
capacity_rebalance(Optional[CapacityRebalanceEnabled], default:None) –Enables or disables Capacity Rebalancing. If Capacity Rebalancing is disabled, proactive replacement of at-risk Spot Instances does not occur. For more information, see Capacity Rebalancing in Auto Scaling to replace at-risk Spot Instances in the Amazon EC2 Auto Scaling User Guide.
To suspend rebalancing across Availability Zones, use the SuspendProcesses API.
-
context(Optional[Context], default:None) –Reserved.
-
desired_capacity_type(Optional[XmlStringMaxLen255], default:None) –The unit of measurement for the value specified for desired capacity. Amazon EC2 Auto Scaling supports
DesiredCapacityTypefor attribute-based instance type selection only. For more information, see Create a mixed instances group using attribute-based instance type selection in the Amazon EC2 Auto Scaling User Guide.By default, Amazon EC2 Auto Scaling specifies
units, which translates into number of instances.Valid values:
units|vcpu|memory-mib -
default_instance_warmup(Optional[DefaultInstanceWarmup], default:None) –The amount of time, in seconds, until a new instance is considered to have finished initializing and resource consumption to become stable after it enters the
InServicestate.During an instance refresh, Amazon EC2 Auto Scaling waits for the warm-up period after it replaces an instance before it moves on to replacing the next instance. Amazon EC2 Auto Scaling also waits for the warm-up period before aggregating the metrics for new instances with existing instances in the Amazon CloudWatch metrics that are used for scaling, resulting in more reliable usage data. For more information, see Set the default instance warmup for an Auto Scaling group in the Amazon EC2 Auto Scaling User Guide.
To manage various warm-up settings at the group level, we recommend that you set the default instance warmup, even if it is set to 0 seconds. To remove a value that you previously set, include the property but specify
-1for the value. However, we strongly recommend keeping the default instance warmup enabled by specifying a value of0or other nominal value. -
instance_maintenance_policy(Optional[InstanceMaintenancePolicy], default:None) –An instance maintenance policy. For more information, see Set instance maintenance policy in the Amazon EC2 Auto Scaling User Guide.
-
availability_zone_distribution(Optional[AvailabilityZoneDistribution], default:None) –The instance capacity distribution across Availability Zones.
-
availability_zone_impairment_policy(Optional[AvailabilityZoneImpairmentPolicy], default:None) –The policy for Availability Zone impairment.
-
skip_zonal_shift_validation(Optional[SkipZonalShiftValidation], default:None) –If you enable zonal shift with cross-zone disabled load balancers, capacity could become imbalanced across Availability Zones. To skip the validation, specify
true. For more information, see Auto Scaling group zonal shift in the Amazon EC2 Auto Scaling User Guide. -
capacity_reservation_specification(Optional[CapacityReservationSpecification], default:None) –The capacity reservation specification for the Auto Scaling group.
-
instance_lifecycle_policy(Optional[InstanceLifecyclePolicy], default:None) –The instance lifecycle policy for the Auto Scaling group. This policy controls instance behavior when an instance transitions through its lifecycle states. Configure retention triggers to specify when instances should move to a
Retainedstate instead of automatic termination.For more information, see Control instance retention with instance lifecycle policies in the Amazon EC2 Auto Scaling User Guide.
-
deletion_protection(Optional[DeletionProtection], default:None) –The deletion protection setting for the Auto Scaling group. This setting helps safeguard your Auto Scaling group and its instances by controlling whether the
DeleteAutoScalingGroupoperation is allowed. When deletion protection is enabled, users cannot delete the Auto Scaling group according to the specified protection level until the setting is changed back to a less restrictive level.The valid values are
none,prevent-force-deletion, andprevent-all-deletion.Default:
noneFor more information, see Configure deletion protection for your Amazon EC2 Auto Scaling resources in the Amazon EC2 Auto Scaling User Guide.
Raises:
-
ResourceContentionFault–You already have a pending update to an Amazon EC2 Auto Scaling resource (for example, an Auto Scaling group, instance, or load balancer).
-
ScalingActivityInProgressFault–The operation can't be performed because there are scaling activities in progress.
-
ServiceLinkedRoleFailure–The service-linked role is not yet ready for use.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To update an Auto Scaling group This example updates multiple properties at the same time.
>>> client.update_auto_scaling_group(auto_scaling_group_name='my-auto-scaling-group', launch_template={'LaunchTemplateName': 'my-template-for-auto-scaling', 'Version': '2'}, min_size=1, max_size=5, new_instances_protected_from_scale_in=True)
Source code in docs_src/capo_auto_scaling/_services/auto_scaling.py
5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 | |