updateAutoScalingGroup
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.
Samples
import aws.sdk.kotlin.services.autoscaling.model.LaunchTemplateSpecification
fun main() {
//sampleStart
// This example updates multiple properties at the same time.
autoScalingClient.updateAutoScalingGroup {
autoScalingGroupName = "my-auto-scaling-group"
launchTemplate = LaunchTemplateSpecification {
launchTemplateName = "my-template-for-auto-scaling"
version = "2"
}
minSize = 1
maxSize = 5
newInstancesProtectedFromScaleIn = true
}
//sampleEnd
}