DetachInstances与 a 一起使用 CLI - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

DetachInstances与 a 一起使用 CLI

以下代码示例演示如何使用 DetachInstances

CLI
AWS CLI

将实例与自动扩缩组分离

此示例将指定实例与指定的自动扩缩组分离。

aws autoscaling detach-instances \ --instance-ids i-030017cfa84b20135 \ --auto-scaling-group-name my-asg \ --should-decrement-desired-capacity

输出:

{ "Activities": [ { "ActivityId": "5091cb52-547a-47ce-a236-c9ccbc2cb2c9", "AutoScalingGroupName": "my-asg", "Description": "Detaching EC2 instance: i-030017cfa84b20135", "Cause": "At 2020-10-31T17:35:04Z instance i-030017cfa84b20135 was detached in response to a user request, shrinking the capacity from 2 to 1.", "StartTime": "2020-04-12T15:02:16.179Z", "StatusCode": "InProgress", "Progress": 50, "Details": "{\"Subnet ID\":\"subnet-6194ea3b\",\"Availability Zone\":\"us-west-2c\"}" } ] }
PowerShell
用于 PowerShell

示例 1:此示例将指定的实例与指定的自动扩缩组分离,并减少所需容量以使 Auto Scaling 不启动替换实例。

Dismount-ASInstance -InstanceId i-93633f9b -AutoScalingGroupName my-asg -ShouldDecrementDesiredCapacity $true

输出:

ActivityId : 06733445-ce94-4039-be1b-b9f1866e276e AutoScalingGroupName : my-asg Cause : At 2015-11-20T22:34:59Z instance i-93633f9b was detached in response to a user request, shrinking the capacity from 2 to 1. Description : Detaching EC2 instance: i-93633f9b Details : {"Availability Zone":"us-west-2b","Subnet ID":"subnet-5264e837"} EndTime : Progress : 50 StartTime : 11/20/2015 2:34:59 PM StatusCode : InProgress StatusMessage :

示例 2:此示例将在不减少所需容量的情况下将指定的实例与指定的自动扩缩组分离。Auto Scaling 会启动一个替换实例。

Dismount-ASInstance -InstanceId i-7bf746a2 -AutoScalingGroupName my-asg -ShouldDecrementDesiredCapacity $false

输出:

ActivityId : f43a3cd4-d38c-4af7-9fe0-d76ec2307b6d AutoScalingGroupName : my-asg Cause : At 2015-11-20T22:34:59Z instance i-7bf746a2 was detached in response to a user request. Description : Detaching EC2 instance: i-7bf746a2 Details : {"Availability Zone":"us-west-2b","Subnet ID":"subnet-5264e837"} EndTime : Progress : 50 StartTime : 11/20/2015 2:34:59 PM StatusCode : InProgress StatusMessage :
  • 有关API详细信息,请参阅 AWS Tools for PowerShell Cmdlet 参考DetachInstances中的。