

# 使用 AWS CLI 的 Auto Scaling 示例
<a name="cli_auto-scaling_code_examples"></a>

以下代码示例演示了如何通过将 AWS Command Line Interface与 Auto Scaling 结合使用，来执行操作和实现常见场景。

*操作是大型程序的代码摘录*，必须在上下文中运行。您可以通过操作了解如何调用单个服务函数，还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接，您可以从中找到有关如何在上下文中设置和运行代码的说明。

**Topics**
+ [操作](#actions)

## 操作
<a name="actions"></a>

### `attach-instances`
<a name="auto-scaling_AttachInstances_cli_topic"></a>

以下代码示例演示了如何使用 `attach-instances`。

**AWS CLI**  
**将实例附加到自动扩缩组**  
此示例将指定的实例附加到指定的自动扩缩组。  

```
aws autoscaling attach-instances \
    --instance-ids i-061c63c5eb45f0416 \
    --auto-scaling-group-name my-asg
```
此命令不生成任何输出。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [AttachInstances](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/attach-instances.html)。

### `attach-load-balancer-target-groups`
<a name="auto-scaling_AttachLoadBalancerTargetGroups_cli_topic"></a>

以下代码示例演示了如何使用 `attach-load-balancer-target-groups`。

**AWS CLI**  
**将目标组附加到自动扩缩组**  
此示例将指定目标组附加到指定的自动扩缩组。  

```
aws autoscaling attach-load-balancer-target-groups \
    --auto-scaling-group-name my-asg \
    --target-group-arns arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[弹性负载均衡和 Amazon EC2 Auto Scaling](https://docs.aws.amazon.com/autoscaling/ec2/userguide/autoscaling-load-balancer.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [AttachLoadBalancerTargetGroups](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/attach-load-balancer-target-groups.html)。

### `attach-load-balancers`
<a name="auto-scaling_AttachLoadBalancers_cli_topic"></a>

以下代码示例演示了如何使用 `attach-load-balancers`。

**AWS CLI**  
**将经典负载均衡器附加到自动扩缩组**  
此示例将指定的经典负载均衡器附加到指定的自动扩缩组。  

```
aws autoscaling attach-load-balancers \
    --load-balancer-names my-load-balancer \
    --auto-scaling-group-name my-asg
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[弹性负载均衡和 Amazon EC2 Auto Scaling](https://docs.aws.amazon.com/autoscaling/ec2/userguide/autoscaling-load-balancer.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [AttachLoadBalancers](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/attach-load-balancers.html)。

### `cancel-instance-refresh`
<a name="auto-scaling_CancelInstanceRefresh_cli_topic"></a>

以下代码示例演示了如何使用 `cancel-instance-refresh`。

**AWS CLI**  
**取消实例刷新**  
以下 `cancel-instance-refresh` 示例取消指定自动扩缩组正在进行的实例刷新。  

```
aws autoscaling cancel-instance-refresh \
    --auto-scaling-group-name my-asg
```
输出：  

```
{
    "InstanceRefreshId": "08b91cf7-8fa6-48af-b6a6-d227f40f1b9b"
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[取消实例刷新](https://docs.aws.amazon.com/autoscaling/ec2/userguide/cancel-instance-refresh.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CancelInstanceRefresh](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/cancel-instance-refresh.html)。

### `complete-lifecycle-action`
<a name="auto-scaling_CompleteLifecycleAction_cli_topic"></a>

以下代码示例演示了如何使用 `complete-lifecycle-action`。

**AWS CLI**  
**完成生命周期操作**  
此示例通知 Amazon EC2 Auto Scaling 指定的生命周期操作已完成，因此它可以完成启动或终止实例。  

```
aws autoscaling complete-lifecycle-action \
    --lifecycle-hook-name my-launch-hook \
    --auto-scaling-group-name my-asg \
    --lifecycle-action-result CONTINUE \
    --lifecycle-action-token bcd2f1b8-9a78-44d3-8a7a-4dd07d7cf635
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [Amazon EC2 Auto Scaling 生命周期挂钩](https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CompleteLifecycleAction](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/complete-lifecycle-action.html)。

### `create-auto-scaling-group`
<a name="auto-scaling_CreateAutoScalingGroup_cli_topic"></a>

以下代码示例演示了如何使用 `create-auto-scaling-group`。

**AWS CLI**  
**示例 1：创建自动扩缩组**  
以下 `create-auto-scaling-group` 示例在区域内多个可用区中的子网中创建自动扩缩组。实例以指定启动模板的默认版本启动。请注意，大多数其他设置都使用默认值，例如，终止策略和运行状况检查配置。  

```
aws autoscaling create-auto-scaling-group \
    --auto-scaling-group-name my-asg \
    --launch-template LaunchTemplateId=lt-1234567890abcde12 \
    --min-size 1 \
    --max-size 5 \
    --vpc-zone-identifier "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782"
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[自动扩缩组](https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html)。  
**示例 2：附加应用程序负载均衡器、网络负载均衡器或网关负载均衡器**  
此示例为支持预期流量的负载均衡器指定目标组的 ARN。运行状况检查类型指定 `ELB`，以便在 Elastic Load Balancing 报告实例运行状况不佳时，自动扩缩组将取代它。该命令还定义了以 `600` 秒为单位的运行状况检查宽限期。宽限期有助于防止新启动的实例过早终止。  

```
aws autoscaling create-auto-scaling-group \
    --auto-scaling-group-name my-asg \
    --launch-template LaunchTemplateId=lt-1234567890abcde12 \
    --target-group-arns arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/943f017f100becff \
    --health-check-type ELB \
    --health-check-grace-period 600 \
    --min-size 1 \
    --max-size 5 \
    --vpc-zone-identifier "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782"
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [Elastic Load Balancing 和 Amazon EC2 Auto Scaling](https://docs.aws.amazon.com/autoscaling/ec2/userguide/autoscaling-load-balancer.html)。  
**示例 3：指定置放群组，并使用最新版本的启动模板**  
此示例将实例启动到单个可用区中的置放群组。这对于具有 HPC 工作负载的低延迟群组很有用。此示例还将指定群组的最小大小、最大大小和所需容量。  

```
aws autoscaling create-auto-scaling-group \
    --auto-scaling-group-name my-asg \
    --launch-template LaunchTemplateId=lt-1234567890abcde12,Version='$Latest' \
    --min-size 1 \
    --max-size 5 \
    --desired-capacity 3 \
    --placement-group my-placement-group \
    --vpc-zone-identifier "subnet-6194ea3b"
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 用户指南（适用于 Linux 实例）》**中的[置放群组](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/placement-groups.html)。  
**示例 4：指定单个实例自动扩缩组，并使用特定版本的启动模板**  
此示例创建一个自动扩缩组，并将其最小和最大容量均设置为 `1` 以强制运行一个实例。该命令还指定了启动模板的 v1，其中指定了现有 ENI 的 ID。当您使用为 eth0 指定现有 ENI 的启动模板时，必须为自动扩缩组指定与网络接口匹配的可用区，而无需在请求中同时指定子网 ID。  

```
aws autoscaling create-auto-scaling-group \
    --auto-scaling-group-name my-asg-single-instance \
    --launch-template LaunchTemplateName=my-template-for-auto-scaling,Version='1' \
    --min-size 1 \
    --max-size 1 \
    --availability-zones us-west-2a
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[自动扩缩组](https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html)。  
**示例 5：指定不同的终止策略**  
此示例使用启动配置创建自动扩缩组，并将终止策略设置为首先终止最旧的实例。该命令还将标签应用于该组及其实例，其密钥为 `Role`，值为 `WebServer`。  

```
aws autoscaling create-auto-scaling-group \
    --auto-scaling-group-name my-asg \
    --launch-configuration-name my-lc \
    --min-size 1 \
    --max-size 5 \
    --termination-policies "OldestInstance" \
    --tags "ResourceId=my-asg,ResourceType=auto-scaling-group,Key=Role,Value=WebServer,PropagateAtLaunch=true" \
    --vpc-zone-identifier "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782"
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[使用 Amazon EC2 Auto Scaling 终止策略](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-termination-policies.html)。  
**示例 6：指定启动生命周期挂钩**  
此示例将使用生命周期挂钩创建一个自动扩缩组，该挂钩支持在实例启动时的自定义操作。  

```
aws autoscaling create-auto-scaling-group \
    --cli-input-json file://~/config.json
```
`config.json` 文件的内容：  

```
{
    "AutoScalingGroupName": "my-asg",
    "LaunchTemplate": {
        "LaunchTemplateId": "lt-1234567890abcde12"
    },
    "LifecycleHookSpecificationList": [{
        "LifecycleHookName": "my-launch-hook",
        "LifecycleTransition": "autoscaling:EC2_INSTANCE_LAUNCHING",
        "NotificationTargetARN": "arn:aws:sqs:us-west-2:123456789012:my-sqs-queue",
        "RoleARN": "arn:aws:iam::123456789012:role/my-notification-role",
        "NotificationMetadata": "SQS message metadata",
        "HeartbeatTimeout": 4800,
        "DefaultResult": "ABANDON"
    }],
    "MinSize": 1,
    "MaxSize": 5,
    "VPCZoneIdentifier": "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782",
    "Tags": [{
        "ResourceType": "auto-scaling-group",
        "ResourceId": "my-asg",
        "PropagateAtLaunch": true,
        "Value": "test",
        "Key": "environment"
    }]
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [Amazon EC2 Auto Scaling 生命周期挂钩](https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html)。  
**示例 7：指定终止生命周期挂钩**  
此示例将使用生命周期挂钩创建一个自动扩缩组，该挂钩支持在实例终止时的自定义操作。  

```
aws autoscaling create-auto-scaling-group \
    --cli-input-json file://~/config.json
```
 的内容`config.json`：  

```
{
    "AutoScalingGroupName": "my-asg",
    "LaunchTemplate": {
        "LaunchTemplateId": "lt-1234567890abcde12"
    },
    "LifecycleHookSpecificationList": [{
        "LifecycleHookName": "my-termination-hook",
        "LifecycleTransition": "autoscaling:EC2_INSTANCE_TERMINATING",
        "HeartbeatTimeout": 120,
        "DefaultResult": "CONTINUE"
    }],
    "MinSize": 1,
    "MaxSize": 5,
    "TargetGroupARNs": [
        "arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"
    ],
    "VPCZoneIdentifier": "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782"
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [Amazon EC2 Auto Scaling 生命周期挂钩](https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html)。  
**示例 8：指定自定义终止策略**  
此示例创建一个自动扩缩组，该组指定自定义 Lambda 函数终止策略，以指示 Amazon EC2 Auto Scaling 哪些实例可以安全地在横向缩减时终止。  

```
aws autoscaling create-auto-scaling-group \
    --auto-scaling-group-name my-asg-single-instance \
    --launch-template LaunchTemplateName=my-template-for-auto-scaling \
    --min-size 1 \
    --max-size 5 \
    --termination-policies "arn:aws:lambda:us-west-2:123456789012:function:HelloFunction:prod" \
    --vpc-zone-identifier "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782"
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[通过 Lambda 创建自定义终止策略](https://docs.aws.amazon.com/autoscaling/ec2/userguide/lambda-custom-termination-policy.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateAutoScalingGroup](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/create-auto-scaling-group.html)。

### `create-launch-configuration`
<a name="auto-scaling_CreateLaunchConfiguration_cli_topic"></a>

以下代码示例演示了如何使用 `create-launch-configuration`。

**AWS CLI**  
**示例 1：创建启动配置**  
此示例创建一个简单的启动配置。  

```
aws autoscaling create-launch-configuration \
    --launch-configuration-name my-lc \
    --image-id ami-04d5cc9b88example \
    --instance-type m5.large
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[创建启动配置](https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-launch-config.html)。  
**示例 2：使用安全组、密钥对和引导脚本创建启动配置**  
此示例使用用户数据中包含的安全组、密钥对和引导脚本创建启动配置。  

```
aws autoscaling create-launch-configuration \
    --launch-configuration-name my-lc \
    --image-id ami-04d5cc9b88example \
    --instance-type m5.large \
    --security-groups sg-eb2af88example \
    --key-name my-key-pair \
    --user-data file://myuserdata.txt
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[创建启动配置](https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-launch-config.html)。  
**示例 3：使用 IAM 角色创建启动配置**  
此示例使用 IAM 角色的实例配置文件名称创建启动配置。  

```
aws autoscaling create-launch-configuration \
    --launch-configuration-name my-lc \
    --image-id ami-04d5cc9b88example \
    --instance-type m5.large \
    --iam-instance-profile my-autoscaling-role
```
此命令不生成任何输出。  
有关更多信息，请参阅 *Amazon EC2 Auto Scaling 用户指南* 中的[针对在 Amazon EC2 实例中运行的应用程序的 IAM 角色](https://docs.aws.amazon.com/autoscaling/ec2/userguide/us-iam-role.html)。  
**示例 4：创建启用详细监控的启动配置**  
此示例创建启用 EC2 详细监控的启动配置，该监控在 1 分钟内将 EC2 指标发送到 CloudWatch。  

```
aws autoscaling create-launch-configuration \
    --launch-configuration-name my-lc \
    --image-id ami-04d5cc9b88example \
    --instance-type m5.large \
    --instance-monitoring Enabled=true
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[配置自动扩缩实例的监控](https://docs.aws.amazon.com/autoscaling/ec2/userguide/enable-as-instance-metrics.html)。  
**示例 5：创建启动竞价型实例的启动配置**  
此示例创建使用竞价型实例作为唯一购买选项的启动配置。  

```
aws autoscaling create-launch-configuration \
    --launch-configuration-name my-lc \
    --image-id ami-04d5cc9b88example \
    --instance-type m5.large \
    --spot-price "0.50"
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[请求竞价型实例](https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-launch-spot-instances.html)。  
**示例 6：使用 EC2 实例创建启动配置**  
此示例基于现有实例的属性创建启动配置。它通过包含 `--placement-tenancy` 和 `--no-associate-public-ip-address` 选项来覆盖置放租赁以及是否设置公有 IP 地址。  

```
aws autoscaling create-launch-configuration \
    --launch-configuration-name my-lc-from-instance \
    --instance-id i-0123a456700123456 \
    --instance-type m5.large \
    --no-associate-public-ip-address \
    --placement-tenancy dedicated
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[使用 EC2 实例创建启动配置](https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-lc-with-instanceID.html)。  
**示例 7：为 Amazon EBS 卷创建具有块设备映射的启动配置**  
此示例为设备名称为 `/dev/sdh` 和卷大小为 20 的 Amazon EBS `gp3` 卷创建具有块设备映射的启动配置。  

```
aws autoscaling create-launch-configuration \
    --launch-configuration-name my-lc \
    --image-id ami-04d5cc9b88example \
    --instance-type m5.large \
    --block-device-mappings '[{"DeviceName":"/dev/sdh","Ebs":{"VolumeSize":20,"VolumeType":"gp3"}}]'
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling API Reference》**中的 [EBS](https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_Ebs.html)。  
有关引用 JSON 格式参数值的信息，请参阅《AWS 命令行界面用户指南》**中的[在 AWS CLI 中使用字符串的引号](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters-quoting-strings.html)。  
**示例 8：为实例存储卷创建具有块设备映射的启动配置**  
此示例创建一个启动配置，将 `ephemeral1` 作为实例存储卷，设备名称为 `/dev/sdc`。  

```
aws autoscaling create-launch-configuration \
    --launch-configuration-name my-lc \
    --image-id ami-04d5cc9b88example \
    --instance-type m5.large \
    --block-device-mappings '[{"DeviceName":"/dev/sdc","VirtualName":"ephemeral1"}]'
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling API Reference》**中的 [BlockDeviceMapping](https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_BlockDeviceMapping.html)。  
有关引用 JSON 格式参数值的信息，请参阅《AWS 命令行界面用户指南》**中的[在 AWS CLI 中使用字符串的引号](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters-quoting-strings.html)。  
**示例 9：创建启动配置并禁止在启动时附加块设备**  
此示例创建一个启动配置，用于禁止通过 AMI 的块设备映射指定的块设备（例如，`/dev/sdf`）。  

```
aws autoscaling create-launch-configuration \
    --launch-configuration-name my-lc \
    --image-id ami-04d5cc9b88example \
    --instance-type m5.large \
    --block-device-mappings '[{"DeviceName":"/dev/sdf","NoDevice":""}]'
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling API Reference》**中的 [BlockDeviceMapping](https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_BlockDeviceMapping.html)。  
有关引用 JSON 格式参数值的信息，请参阅《AWS 命令行界面用户指南》**中的[在 AWS CLI 中使用字符串的引号](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters-quoting-strings.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateLaunchConfiguration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/create-launch-configuration.html)。

### `create-or-update-tags`
<a name="auto-scaling_CreateOrUpdateTags_cli_topic"></a>

以下代码示例演示了如何使用 `create-or-update-tags`。

**AWS CLI**  
**创建或更新自动扩缩组的标签**  
此示例向指定的自动扩缩组添加两个标签。  

```
aws autoscaling create-or-update-tags \
    --tags ResourceId=my-asg,ResourceType=auto-scaling-group,Key=Role,Value=WebServer,PropagateAtLaunch=true ResourceId=my-asg,ResourceType=auto-scaling-group,Key=Dept,Value=Research,PropagateAtLaunch=true
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[标记自动扩缩组和实例](https://docs.aws.amazon.com/autoscaling/ec2/userguide/autoscaling-tagging.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateOrUpdateTags](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/create-or-update-tags.html)。

### `delete-auto-scaling-group`
<a name="auto-scaling_DeleteAutoScalingGroup_cli_topic"></a>

以下代码示例演示了如何使用 `delete-auto-scaling-group`。

**AWS CLI**  
**示例 1：删除指定的自动扩缩组**  
此示例将删除指定的自动扩缩组。  

```
aws autoscaling delete-auto-scaling-group \
    --auto-scaling-group-name my-asg
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[删除自动扩缩基础设施](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-process-shutdown.html)。  
**示例 2：强制删除指定的自动扩缩组**  
要在不等待自动扩缩组中的实例终止的情况下删除该组，请使用 `--force-delete` 选项。  

```
aws autoscaling delete-auto-scaling-group \
    --auto-scaling-group-name my-asg \
    --force-delete
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[删除自动扩缩基础设施](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-process-shutdown.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteAutoScalingGroup](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/delete-auto-scaling-group.html)。

### `delete-launch-configuration`
<a name="auto-scaling_DeleteLaunchConfiguration_cli_topic"></a>

以下代码示例演示了如何使用 `delete-launch-configuration`。

**AWS CLI**  
**删除启动配置**  
此示例删除指定的启动配置。  

```
aws autoscaling delete-launch-configuration \
    --launch-configuration-name my-launch-config
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[删除自动扩缩基础设施](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-process-shutdown.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteLaunchConfiguration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/delete-launch-configuration.html)。

### `delete-lifecycle-hook`
<a name="auto-scaling_DeleteLifecycleHook_cli_topic"></a>

以下代码示例演示了如何使用 `delete-lifecycle-hook`。

**AWS CLI**  
**删除生命周期挂钩**  
此示例删除指定的生命周期挂钩。  

```
aws autoscaling delete-lifecycle-hook \
    --lifecycle-hook-name my-lifecycle-hook \
    --auto-scaling-group-name my-asg
```
此命令不生成任何输出。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteLifecycleHook](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/delete-lifecycle-hook.html)。

### `delete-notification-configuration`
<a name="auto-scaling_DeleteNotificationConfiguration_cli_topic"></a>

以下代码示例演示了如何使用 `delete-notification-configuration`。

**AWS CLI**  
**删除 Auto Scaling 通知**  
此示例删除指定自动扩缩组的指定通知。  

```
aws autoscaling delete-notification-configuration \
    --auto-scaling-group-name my-asg \
    --topic-arn arn:aws:sns:us-west-2:123456789012:my-sns-topic
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[删除通知配置](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ASGettingNotifications.html#delete-settingupnotifications)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteNotificationConfiguration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/delete-notification-configuration.html)。

### `delete-policy`
<a name="auto-scaling_DeletePolicy_cli_topic"></a>

以下代码示例演示了如何使用 `delete-policy`。

**AWS CLI**  
**删除扩展策略**  
此示例删除指定的扩展策略。  

```
aws autoscaling delete-policy \
    --auto-scaling-group-name my-asg \
    --policy-name alb1000-target-tracking-scaling-policy
```
此命令不生成任何输出。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考**》中的 [DeletePolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/delete-policy.html)。

### `delete-scheduled-action`
<a name="auto-scaling_DeleteScheduledAction_cli_topic"></a>

以下代码示例演示了如何使用 `delete-scheduled-action`。

**AWS CLI**  
**从自动扩缩组中删除计划的操作**  
此示例从指定的自动扩缩组删除指定的计划操作。  

```
aws autoscaling delete-scheduled-action \
    --auto-scaling-group-name my-asg \
    --scheduled-action-name my-scheduled-action
```
此命令不生成任何输出。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteScheduledAction](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/delete-scheduled-action.html)。

### `delete-tags`
<a name="auto-scaling_DeleteTags_cli_topic"></a>

以下代码示例演示了如何使用 `delete-tags`。

**AWS CLI**  
**从自动扩缩组中删除标签**  
此示例从指定的自动扩缩组删除指定的标签。  

```
aws autoscaling delete-tags \
    --tags ResourceId=my-asg,ResourceType=auto-scaling-group,Key=Dept,Value=Research
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[标记自动扩缩组和实例](https://docs.aws.amazon.com/autoscaling/ec2/userguide/autoscaling-tagging.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteTags](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/delete-tags.html)。

### `delete-warm-pool`
<a name="auto-scaling_DeleteWarmPool_cli_topic"></a>

以下代码示例演示了如何使用 `delete-warm-pool`。

**AWS CLI**  
**示例 1：删除热池**  
以下示例删除指定自动扩缩组的热池。  

```
aws autoscaling delete-warm-pool \
    --auto-scaling-group-name my-asg
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [Amazon EC2 Auto Scaling 的热池](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-warm-pools.html)。  
**示例 2：强制删除热池**  
要在不等待其实例终止的情况下删除热池，请使用 `--force-delete` 选项。  

```
aws autoscaling delete-warm-pool \
    --auto-scaling-group-name my-asg \
    --force-delete
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [Amazon EC2 Auto Scaling 的热池](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-warm-pools.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteWarmPool](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/delete-warm-pool.html)。

### `describe-account-limits`
<a name="auto-scaling_DescribeAccountLimits_cli_topic"></a>

以下代码示例演示了如何使用 `describe-account-limits`。

**AWS CLI**  
**描述您的 Amazon EC2 Auto Scaling 账户限制**  
此示例描述您的 AWS 账户的 Amazon EC2 Auto Scaling 限制。  

```
aws autoscaling describe-account-limits
```
输出：  

```
{
    "NumberOfLaunchConfigurations": 5,
    "MaxNumberOfLaunchConfigurations": 100,
    "NumberOfAutoScalingGroups": 3,
    "MaxNumberOfAutoScalingGroups": 20
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [Amazon EC2 Auto Scaling 服务配额](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-account-limits.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeAccountLimits](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-account-limits.html)。

### `describe-adjustment-types`
<a name="auto-scaling_DescribeAdjustmentTypes_cli_topic"></a>

以下代码示例演示了如何使用 `describe-adjustment-types`。

**AWS CLI**  
**描述可用的扩展调整类型**  
此示例描述可用的调整类型。  

```
aws autoscaling describe-adjustment-types
```
输出：  

```
{
    "AdjustmentTypes": [
        {
            "AdjustmentType": "ChangeInCapacity"
        },
        {
            "AdjustmentType": "ExactCapacity"
        },
        {
            "AdjustmentType": "PercentChangeInCapacity"
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[扩展调整类型](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scaling-simple-step.html#as-scaling-adjustment)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeAdjustmentTypes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-adjustment-types.html)。

### `describe-auto-scaling-groups`
<a name="auto-scaling_DescribeAutoScalingGroups_cli_topic"></a>

以下代码示例演示了如何使用 `describe-auto-scaling-groups`。

**AWS CLI**  
**示例 1：描述指定的自动扩缩组**  
此示例将描述指定的自动扩缩组。  

```
aws autoscaling describe-auto-scaling-groups \
    --auto-scaling-group-names my-asg
```
输出：  

```
{
    "AutoScalingGroups": [
        {
            "AutoScalingGroupName": "my-asg",
            "AutoScalingGroupARN": "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:930d940e-891e-4781-a11a-7b0acd480f03:autoScalingGroupName/my-asg",
            "LaunchTemplate": {
                "LaunchTemplateName": "my-launch-template",
                "Version": "1",
                "LaunchTemplateId": "lt-1234567890abcde12"
            },
            "MinSize": 0,
            "MaxSize": 1,
            "DesiredCapacity": 1,
            "DefaultCooldown": 300,
            "AvailabilityZones": [
                "us-west-2a",
                "us-west-2b",
                "us-west-2c"
            ],
            "LoadBalancerNames": [],
            "TargetGroupARNs": [],
            "HealthCheckType": "EC2",
            "HealthCheckGracePeriod": 0,
            "Instances": [
                {
                    "InstanceId": "i-06905f55584de02da",
                    "InstanceType": "t2.micro",
                    "AvailabilityZone": "us-west-2a",
                    "HealthStatus": "Healthy",
                    "LifecycleState": "InService",
                    "ProtectedFromScaleIn": false,
                    "LaunchTemplate": {
                        "LaunchTemplateName": "my-launch-template",
                        "Version": "1",
                        "LaunchTemplateId": "lt-1234567890abcde12"
                    }
                }
            ],
            "CreatedTime": "2023-10-28T02:39:22.152Z",
            "SuspendedProcesses": [],
            "VPCZoneIdentifier": "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782",
            "EnabledMetrics": [],
            "Tags": [],
            "TerminationPolicies": [
                "Default"
            ],
            "NewInstancesProtectedFromScaleIn": false,
            "ServiceLinkedRoleARN":"arn",
            "TrafficSources": []
        }
    ]
}
```
**示例 2：描述前 100 个指定的自动扩缩组**  
此示例将描述指定的自动扩缩组。它允许您指定最多 100 个组名称。  

```
aws autoscaling describe-auto-scaling-groups \
    --max-items 100 \
    --auto-scaling-group-names "group1" "group2" "group3" "group4"
```
有关输出示例，请参阅示例 1。  
**示例 3：描述指定区域中的自动扩缩组**  
此示例将描述指定区域中的自动扩缩组（最多 75 个组）。  

```
aws autoscaling describe-auto-scaling-groups \
    --max-items 75 \
    --region us-east-1
```
有关输出示例，请参阅示例 1。  
**示例 4：描述指定数量的自动扩缩组**  
要返回特定数量的自动扩缩组，请使用 `--max-items` 选项。  

```
aws autoscaling describe-auto-scaling-groups \
    --max-items 1
```
有关输出示例，请参阅示例 1。  
如果输出包含 `NextToken` 字段，则可描述更多组。要获取其他组，请在后续调用中使用此字段的值和 `--starting-token` 选项，如下所示。  

```
aws autoscaling describe-auto-scaling-groups \
    --starting-token Z3M3LMPEXAMPLE
```
有关输出示例，请参阅示例 1。  
**示例 5：描述使用启动配置的自动扩缩组**  
此示例使用 `--query` 选项描述使用启动配置的自动扩缩组。  

```
aws autoscaling describe-auto-scaling-groups \
    --query 'AutoScalingGroups[?LaunchConfigurationName!=`null`]'
```
输出：  

```
[
    {
        "AutoScalingGroupName": "my-asg",
        "AutoScalingGroupARN": "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:930d940e-891e-4781-a11a-7b0acd480f03:autoScalingGroupName/my-asg",
        "LaunchConfigurationName": "my-lc",
        "MinSize": 0,
        "MaxSize": 1,
        "DesiredCapacity": 1,
        "DefaultCooldown": 300,
        "AvailabilityZones": [
            "us-west-2a",
            "us-west-2b",
            "us-west-2c"
        ],
        "LoadBalancerNames": [],
        "TargetGroupARNs": [],
        "HealthCheckType": "EC2",
        "HealthCheckGracePeriod": 0,
        "Instances": [
            {
                "InstanceId": "i-088c57934a6449037",
                "InstanceType": "t2.micro",
                "AvailabilityZone": "us-west-2c",
                "HealthStatus": "Healthy",
                "LifecycleState": "InService",
                "LaunchConfigurationName": "my-lc",
                "ProtectedFromScaleIn": false
            }
        ],
        "CreatedTime": "2023-10-28T02:39:22.152Z",
        "SuspendedProcesses": [],
        "VPCZoneIdentifier": "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782",
        "EnabledMetrics": [],
        "Tags": [],
        "TerminationPolicies": [
            "Default"
        ],
        "NewInstancesProtectedFromScaleIn": false,
        "ServiceLinkedRoleARN":"arn",
        "TrafficSources": []
    }
]
```
有关更多信息，请参阅《AWS 命令行界面用户指南》**中的[筛选 AWS CLI 输出](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-filter.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeAutoScalingGroups](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-auto-scaling-groups.html)。

### `describe-auto-scaling-instances`
<a name="auto-scaling_DescribeAutoScalingInstances_cli_topic"></a>

以下代码示例演示了如何使用 `describe-auto-scaling-instances`。

**AWS CLI**  
**示例 1：描述一个或多个实例**  
此示例将描述指定的实例。  

```
aws autoscaling describe-auto-scaling-instances \
    --instance-ids i-06905f55584de02da
```
输出：  

```
{
    "AutoScalingInstances": [
        {
            "InstanceId": "i-06905f55584de02da",
            "InstanceType": "t2.micro",
            "AutoScalingGroupName": "my-asg",
            "AvailabilityZone": "us-west-2b",
            "LifecycleState": "InService",
            "HealthStatus": "HEALTHY",
            "ProtectedFromScaleIn": false,
            "LaunchTemplate": {
                "LaunchTemplateId": "lt-1234567890abcde12",
                "LaunchTemplateName": "my-launch-template",
                "Version": "1"
            }
        }
    ]
}
```
**示例 2：描述一个或多个实例**  
此示例使用 `--max-items` 选项来指定通过此调用返回多少个实例。  

```
aws autoscaling describe-auto-scaling-instances \
    --max-items 1
```
如果输出包含 `NextToken` 字段，可返回更多实例。要获取其他实例，请在后续调用中使用此字段的值和 `--starting-token` 选项，如下所示。  

```
aws autoscaling describe-auto-scaling-instances \
    --starting-token Z3M3LMPEXAMPLE
```
有关输出示例，请参阅示例 1。  
**示例 3：描述使用启动配置的实例**  
此示例使用 `--query` 选项描述使用启动配置的实例。  

```
aws autoscaling describe-auto-scaling-instances \
    --query 'AutoScalingInstances[?LaunchConfigurationName!=`null`]'
```
输出：  

```
[
    {
        "InstanceId": "i-088c57934a6449037",
        "InstanceType": "t2.micro",
        "AutoScalingGroupName": "my-asg",
        "AvailabilityZone": "us-west-2c",
        "LifecycleState": "InService",
        "HealthStatus": "HEALTHY",
        "LaunchConfigurationName": "my-lc",
        "ProtectedFromScaleIn": false
    }
]
```
有关更多信息，请参阅《AWS 命令行界面用户指南》**中的[筛选 AWS CLI 输出](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-filter.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeAutoScalingInstances](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-auto-scaling-instances.html)。

### `describe-auto-scaling-notification-types`
<a name="auto-scaling_DescribeAutoScalingNotificationTypes_cli_topic"></a>

以下代码示例演示了如何使用 `describe-auto-scaling-notification-types`。

**AWS CLI**  
**描述可用的通知类型**  
此示例描述可用的通知类型。  

```
aws autoscaling describe-auto-scaling-notification-types
```
输出：  

```
{
    "AutoScalingNotificationTypes": [
        "autoscaling:EC2_INSTANCE_LAUNCH",
        "autoscaling:EC2_INSTANCE_LAUNCH_ERROR",
        "autoscaling:EC2_INSTANCE_TERMINATE",
        "autoscaling:EC2_INSTANCE_TERMINATE_ERROR",
        "autoscaling:TEST_NOTIFICATION"
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[在自动扩缩组扩展时获取 Amazon SNS 通知](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ASGettingNotifications.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeAutoScalingNotificationTypes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-auto-scaling-notification-types.html)。

### `describe-instance-refreshes`
<a name="auto-scaling_DescribeInstanceRefreshes_cli_topic"></a>

以下代码示例演示了如何使用 `describe-instance-refreshes`。

**AWS CLI**  
**描述实例刷新**  
以下 `describe-instance-refreshes` 示例返回指定自动扩缩组的所有实例刷新请求的说明，包括状态消息和（如果有）状态原因。  

```
aws autoscaling describe-instance-refreshes \
    --auto-scaling-group-name my-asg
```
输出：  

```
{
    "InstanceRefreshes": [
        {
            "InstanceRefreshId": "08b91cf7-8fa6-48af-b6a6-d227f40f1b9b",
            "AutoScalingGroupName": "my-asg",
            "Status": "InProgress",
            "StatusReason": "Waiting for instances to warm up before continuing. For example: 0e69cc3f05f825f4f is warming up.",
            "EndTime": "2023-03-23T16:42:55Z",
            "PercentageComplete": 0,
            "InstancesToUpdate": 0,
    "Preferences": {
                "MinHealthyPercentage": 100,
                "InstanceWarmup": 300,
                "CheckpointPercentages": [
                    50
                ],
                "CheckpointDelay": 3600,
                "SkipMatching": false,
                "AutoRollback": true,
                "ScaleInProtectedInstances": "Ignore",
                "StandbyInstances": "Ignore"
            }
        },
        {
            "InstanceRefreshId": "dd7728d0-5bc4-4575-96a3-1b2c52bf8bb1",
            "AutoScalingGroupName": "my-asg",
            "Status": "Successful",
            "EndTime": "2022-06-02T16:53:37Z",
            "PercentageComplete": 100,
            "InstancesToUpdate": 0,
    "Preferences": {
                "MinHealthyPercentage": 90,
                "InstanceWarmup": 300,
                "SkipMatching": true,
                "AutoRollback": true,
                "ScaleInProtectedInstances": "Ignore",
                "StandbyInstances": "Ignore"
            }
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[检查实例刷新的状态](https://docs.aws.amazon.com/en_us/autoscaling/ec2/userguide/check-status-instance-refresh.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeInstanceRefreshes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-instance-refreshes.html)。

### `describe-launch-configurations`
<a name="auto-scaling_DescribeLaunchConfigurations_cli_topic"></a>

以下代码示例演示了如何使用 `describe-launch-configurations`。

**AWS CLI**  
**示例 1：描述指定的启动配置**  
此示例描述指定的启动配置。  

```
aws autoscaling describe-launch-configurations \
    --launch-configuration-names my-launch-config
```
输出：  

```
{
    "LaunchConfigurations": [
        {
            "LaunchConfigurationName": "my-launch-config",
            "LaunchConfigurationARN": "arn:aws:autoscaling:us-west-2:123456789012:launchConfiguration:98d3b196-4cf9-4e88-8ca1-8547c24ced8b:launchConfigurationName/my-launch-config",
            "ImageId": "ami-0528a5175983e7f28",
            "KeyName": "my-key-pair-uswest2",
            "SecurityGroups": [
                "sg-05eaec502fcdadc2e"
            ],
            "ClassicLinkVPCSecurityGroups": [],
            "UserData": "",
            "InstanceType": "t2.micro",
            "KernelId": "",
            "RamdiskId": "",
            "BlockDeviceMappings": [
                {
                    "DeviceName": "/dev/xvda",
                    "Ebs": {
                        "SnapshotId": "snap-06c1606ba5ca274b1",
                        "VolumeSize": 8,
                        "VolumeType": "gp2",
                        "DeleteOnTermination": true,
                        "Encrypted": false
                    }
                }
            ],
            "InstanceMonitoring": {
                "Enabled": true
            },
            "CreatedTime": "2020-10-28T02:39:22.321Z",
            "EbsOptimized": false,
            "AssociatePublicIpAddress": true,
            "MetadataOptions": {
                "HttpTokens": "required",
                "HttpPutResponseHopLimit": 1,
                "HttpEndpoint": "disabled"
            }
        }
    ]
}
```
**示例 2：描述指定数量的启动配置**  
要返回特定数量的启动配置，请使用 `--max-items` 选项。  

```
aws autoscaling describe-launch-configurations \
    --max-items 1
```
如果输出包含 `NextToken` 字段，则可返回更多启动配置。要获取其他启动配置，请在后续调用中使用此字段的值和 `--starting-token` 选项，如下所示。  

```
aws autoscaling describe-launch-configurations \
    --starting-token Z3M3LMPEXAMPLE
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeLaunchConfigurations](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-launch-configurations.html)。

### `describe-lifecycle-hook-types`
<a name="auto-scaling_DescribeLifecycleHookTypes_cli_topic"></a>

以下代码示例演示了如何使用 `describe-lifecycle-hook-types`。

**AWS CLI**  
**描述可用的生命周期挂钩类型**  
此示例描述可用的生命周期挂钩类型。  

```
aws autoscaling describe-lifecycle-hook-types
```
输出：  

```
{
    "LifecycleHookTypes": [
        "autoscaling:EC2_INSTANCE_LAUNCHING",
        "autoscaling:EC2_INSTANCE_TERMINATING"
    ]
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeLifecycleHookTypes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-lifecycle-hook-types.html)。

### `describe-lifecycle-hooks`
<a name="auto-scaling_DescribeLifecycleHooks_cli_topic"></a>

以下代码示例演示了如何使用 `describe-lifecycle-hooks`。

**AWS CLI**  
**描述您的生命周期挂钩**  
此示例描述指定自动扩缩组的生命周期挂钩。  

```
aws autoscaling describe-lifecycle-hooks \
    --auto-scaling-group-name my-asg
```
输出：  

```
{
    "LifecycleHooks": [
        {
            "GlobalTimeout": 3000,
            "HeartbeatTimeout": 30,
            "AutoScalingGroupName": "my-asg",
            "LifecycleHookName": "my-launch-hook",
            "DefaultResult": "ABANDON",
            "LifecycleTransition": "autoscaling:EC2_INSTANCE_LAUNCHING"
        },
        {
            "GlobalTimeout": 6000,
            "HeartbeatTimeout": 60,
            "AutoScalingGroupName": "my-asg",
            "LifecycleHookName": "my-termination-hook",
            "DefaultResult": "CONTINUE",
            "LifecycleTransition": "autoscaling:EC2_INSTANCE_TERMINATING"
        }
    ]
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeLifecycleHooks](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-lifecycle-hooks.html)。

### `describe-load-balancer-target-groups`
<a name="auto-scaling_DescribeLoadBalancerTargetGroups_cli_topic"></a>

以下代码示例演示了如何使用 `describe-load-balancer-target-groups`。

**AWS CLI**  
**描述自动扩缩组的负载均衡器目标组**  
此示例描述附加到指定自动扩缩组的负载均衡器目标组。  

```
aws autoscaling describe-load-balancer-target-groups \
    --auto-scaling-group-name my-asg
```
输出：  

```
{
    "LoadBalancerTargetGroups": [
        {
            "LoadBalancerTargetGroupARN": "arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067",
            "State": "Added"
        }
    ]
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeLoadBalancerTargetGroups](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-load-balancer-target-groups.html)。

### `describe-load-balancers`
<a name="auto-scaling_DescribeLoadBalancers_cli_topic"></a>

以下代码示例演示了如何使用 `describe-load-balancers`。

**AWS CLI**  
**描述自动扩缩组的经典负载均衡器**  
此示例描述指定自动扩缩组的经典负载均衡器。  

```
aws autoscaling describe-load-balancers \
    --auto-scaling-group-name my-asg
```
输出：  

```
{
    "LoadBalancers": [
        {
            "State": "Added",
            "LoadBalancerName": "my-load-balancer"
        }
    ]
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeLoadBalancers](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-load-balancers.html)。

### `describe-metric-collection-types`
<a name="auto-scaling_DescribeMetricCollectionTypes_cli_topic"></a>

以下代码示例演示了如何使用 `describe-metric-collection-types`。

**AWS CLI**  
**描述可用的指标收集类型**  
此示例描述可用的指标收集类型。  

```
aws autoscaling describe-metric-collection-types
```
输出：  

```
{
    "Metrics": [
        {
            "Metric": "GroupMinSize"
        },
        {
            "Metric": "GroupMaxSize"
        },
        {
            "Metric": "GroupDesiredCapacity"
        },
        {
            "Metric": "GroupInServiceInstances"
        },
        {
            "Metric": "GroupInServiceCapacity"
        },
        {
            "Metric": "GroupPendingInstances"
        },
        {
            "Metric": "GroupPendingCapacity"
        },
        {
            "Metric": "GroupTerminatingInstances"
        },
        {
            "Metric": "GroupTerminatingCapacity"
        },
        {
            "Metric": "GroupStandbyInstances"
        },
        {
            "Metric": "GroupStandbyCapacity"
        },
        {
            "Metric": "GroupTotalInstances"
        },
        {
            "Metric": "GroupTotalCapacity"
        }
    ],
    "Granularities": [
        {
            "Granularity": "1Minute"
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[自动扩缩组指标](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-instance-monitoring.html#as-group-metrics)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeMetricCollectionTypes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-metric-collection-types.html)。

### `describe-notification-configurations`
<a name="auto-scaling_DescribeNotificationConfigurations_cli_topic"></a>

以下代码示例演示了如何使用 `describe-notification-configurations`。

**AWS CLI**  
**示例 1：描述指定组的通知配置**  
此示例描述指定自动扩缩组的通知配置。  

```
aws autoscaling describe-notification-configurations \
    --auto-scaling-group-name my-asg
```
输出：  

```
{
    "NotificationConfigurations": [
        {
            "AutoScalingGroupName": "my-asg",
            "NotificationType": "autoscaling:TEST_NOTIFICATION",
            "TopicARN": "arn:aws:sns:us-west-2:123456789012:my-sns-topic-2"
        },
        {
            "AutoScalingGroupName": "my-asg",
            "NotificationType": "autoscaling:TEST_NOTIFICATION",
            "TopicARN": "arn:aws:sns:us-west-2:123456789012:my-sns-topic"
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[在自动扩缩组扩展时获取 Amazon SNS 通知](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ASGettingNotifications.html)。  
**示例 1：描述指定数量的通知配置**  
要返回特定数量的通知配置，请使用 `max-items` 参数。  

```
aws autoscaling describe-notification-configurations \
    --auto-scaling-group-name my-auto-scaling-group \
    --max-items 1
```
输出：  

```
{
    "NotificationConfigurations": [
        {
            "AutoScalingGroupName": "my-asg",
            "NotificationType": "autoscaling:TEST_NOTIFICATION",
            "TopicARN": "arn:aws:sns:us-west-2:123456789012:my-sns-topic-2"
        },
        {
            "AutoScalingGroupName": "my-asg",
            "NotificationType": "autoscaling:TEST_NOTIFICATION",
            "TopicARN": "arn:aws:sns:us-west-2:123456789012:my-sns-topic"
        }
    ]
}
```
如果输出包含 `NextToken` 字段，可返回更多通知配置。要获取其他通知配置，请在后续调用中使用此字段的值和 `starting-token` 选项，如下所示。  

```
aws autoscaling describe-notification-configurations \
    --auto-scaling-group-name my-asg \
    --starting-token Z3M3LMPEXAMPLE
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[在自动扩缩组扩展时获取 Amazon SNS 通知](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ASGettingNotifications.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeNotificationConfigurations](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-notification-configurations.html)。

### `describe-policies`
<a name="auto-scaling_DescribePolicies_cli_topic"></a>

以下代码示例演示了如何使用 `describe-policies`。

**AWS CLI**  
**示例 1：描述指定组的扩展策略**  
此示例描述指定自动扩缩组的扩展策略。  

```
aws autoscaling describe-policies \
    --auto-scaling-group-name my-asg
```
输出：  

```
{
    "ScalingPolicies": [
        {
            "AutoScalingGroupName": "my-asg",
            "PolicyName": "alb1000-target-tracking-scaling-policy",
            "PolicyARN": "arn:aws:autoscaling:us-west-2:123456789012:scalingPolicy:3065d9c8-9969-4bec-bb6a-3fbe5550fde6:autoScalingGroupName/my-asg:policyName/alb1000-target-tracking-scaling-policy",
            "PolicyType": "TargetTrackingScaling",
            "StepAdjustments": [],
            "Alarms": [
                {
                    "AlarmName": "TargetTracking-my-asg-AlarmHigh-924887a9-12d7-4e01-8686-6f844d13a196",
                    "AlarmARN": "arn:aws:cloudwatch:us-west-2:123456789012:alarm:TargetTracking-my-asg-AlarmHigh-924887a9-12d7-4e01-8686-6f844d13a196"
                },
                {
                    "AlarmName": "TargetTracking-my-asg-AlarmLow-f96f899d-b8e7-4d09-a010-c1aaa35da296",
                    "AlarmARN": "arn:aws:cloudwatch:us-west-2:123456789012:alarm:TargetTracking-my-asg-AlarmLow-f96f899d-b8e7-4d09-a010-c1aaa35da296"
                }
            ],
            "TargetTrackingConfiguration": {
                "PredefinedMetricSpecification": {
                    "PredefinedMetricType": "ALBRequestCountPerTarget",
                    "ResourceLabel": "app/my-alb/778d41231b141a0f/targetgroup/my-alb-target-group/943f017f100becff"
                },
                "TargetValue": 1000.0,
                "DisableScaleIn": false
            },
            "Enabled": true
        },
        {
            "AutoScalingGroupName": "my-asg",
            "PolicyName": "cpu40-target-tracking-scaling-policy",
            "PolicyARN": "arn:aws:autoscaling:us-west-2:123456789012:scalingPolicy:5fd26f71-39d4-4690-82a9-b8515c45cdde:autoScalingGroupName/my-asg:policyName/cpu40-target-tracking-scaling-policy",
            "PolicyType": "TargetTrackingScaling",
            "StepAdjustments": [],
            "Alarms": [
                {
                    "AlarmName": "TargetTracking-my-asg-AlarmHigh-139f9789-37b9-42ad-bea5-b5b147d7f473",
                    "AlarmARN": "arn:aws:cloudwatch:us-west-2:123456789012:alarm:TargetTracking-my-asg-AlarmHigh-139f9789-37b9-42ad-bea5-b5b147d7f473"
                },
                {
                    "AlarmName": "TargetTracking-my-asg-AlarmLow-bd681c67-fc18-4c56-8468-fb8e413009c9",
                    "AlarmARN": "arn:aws:cloudwatch:us-west-2:123456789012:alarm:TargetTracking-my-asg-AlarmLow-bd681c67-fc18-4c56-8468-fb8e413009c9"
                }
            ],
            "TargetTrackingConfiguration": {
                "PredefinedMetricSpecification": {
                    "PredefinedMetricType": "ASGAverageCPUUtilization"
                },
                "TargetValue": 40.0,
                "DisableScaleIn": false
            },
            "Enabled": true
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[动态扩展](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scale-based-on-demand.html)。  
**示例 2：描述指定名称的扩展策略**  
要返回特定的扩展策略，请使用 `--policy-names` 选项。  

```
aws autoscaling describe-policies \
    --auto-scaling-group-name my-asg \
    --policy-names cpu40-target-tracking-scaling-policy
```
有关输出示例，请参阅示例 1。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[动态扩展](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scale-based-on-demand.html)。  
**示例 3：描述多种扩展策略**  
要返回特定数量的策略，请使用 `--max-items` 选项。  

```
aws autoscaling describe-policies \
    --auto-scaling-group-name my-asg \
    --max-items 1
```
有关输出示例，请参阅示例 1。  
如果输出包含 `NextToken` 字段，则请在后续调用中使用此字段的值和 `--starting-token` 选项获取其他策略。  

```
aws autoscaling describe-policies --auto-scaling-group-name my-asg --starting-token Z3M3LMPEXAMPLE
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[动态扩展](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scale-based-on-demand.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribePolicies](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-policies.html)。

### `describe-scaling-activities`
<a name="auto-scaling_DescribeScalingActivities_cli_topic"></a>

以下代码示例演示了如何使用 `describe-scaling-activities`。

**AWS CLI**  
**示例 1：描述指定组的扩展活动**  
此示例描述指定自动扩缩组的扩展活动。  

```
aws autoscaling describe-scaling-activities \
    --auto-scaling-group-name my-asg
```
输出：  

```
{
    "Activities": [
        {
            "ActivityId": "f9f2d65b-f1f2-43e7-b46d-d86756459699",
            "Description": "Launching a new EC2 instance: i-0d44425630326060f",
            "AutoScalingGroupName": "my-asg",
            "Cause": "At 2020-10-30T19:35:51Z a user request update of AutoScalingGroup constraints to min: 0, max: 16, desired: 16 changing the desired capacity from 0 to 16.  At 2020-10-30T19:36:07Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 0 to 16.",
            "StartTime": "2020-10-30T19:36:09.766Z",
            "EndTime": "2020-10-30T19:36:41Z",
            "StatusCode": "Successful",
            "Progress": 100,
            "Details": "{\"Subnet ID\":\"subnet-5ea0c127\",\"Availability Zone\":\"us-west-2b\"}"
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[验证自动扩缩组的扩展活动](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-verify-scaling-activity.html)。  
**示例 2：描述已删除组的扩展活动**  
要在删除自动扩缩组后描述扩展活动，请添加 `--include-deleted-groups` 选项。  

```
aws autoscaling describe-scaling-activities \
    --auto-scaling-group-name my-asg \
    --include-deleted-groups
```
输出：  

```
{
    "Activities": [
        {
            "ActivityId": "e1f5de0e-f93e-1417-34ac-092a76fba220",
            "Description": "Launching a new EC2 instance.  Status Reason: Your Spot request price of 0.001 is lower than the minimum required Spot request fulfillment price of 0.0031. Launching EC2 instance failed.",
            "AutoScalingGroupName": "my-asg",
            "Cause": "At 2021-01-13T20:47:24Z a user request update of AutoScalingGroup constraints to min: 1, max: 5, desired: 3 changing the desired capacity from 0 to 3.  At 2021-01-13T20:47:27Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 0 to 3.",
            "StartTime": "2021-01-13T20:47:30.094Z",
            "EndTime": "2021-01-13T20:47:30Z",
            "StatusCode": "Failed",
            "StatusMessage": "Your Spot request price of 0.001 is lower than the minimum required Spot request fulfillment price of 0.0031. Launching EC2 instance failed.",
            "Progress": 100,
            "Details": "{\"Subnet ID\":\"subnet-5ea0c127\",\"Availability Zone\":\"us-west-2b\"}",
            "AutoScalingGroupState": "Deleted",
            "AutoScalingGroupARN": "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:283179a2-f3ce-423d-93f6-66bb518232f7:autoScalingGroupName/my-asg"
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[排除 Amazon EC2 Auto Scaling 问题](https://docs.aws.amazon.com/autoscaling/ec2/userguide/CHAP_Troubleshooting.html)。  
**示例 3：描述指定数量的扩展活动**  
要返回特定数量的活动，请使用 `--max-items` 选项。  

```
aws autoscaling describe-scaling-activities \
    --max-items 1
```
输出：  

```
{
    "Activities": [
        {
            "ActivityId": "f9f2d65b-f1f2-43e7-b46d-d86756459699",
            "Description": "Launching a new EC2 instance: i-0d44425630326060f",
            "AutoScalingGroupName": "my-asg",
            "Cause": "At 2020-10-30T19:35:51Z a user request update of AutoScalingGroup constraints to min: 0, max: 16, desired: 16 changing the desired capacity from 0 to 16.  At 2020-10-30T19:36:07Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 0 to 16.",
            "StartTime": "2020-10-30T19:36:09.766Z",
            "EndTime": "2020-10-30T19:36:41Z",
            "StatusCode": "Successful",
            "Progress": 100,
            "Details": "{\"Subnet ID\":\"subnet-5ea0c127\",\"Availability Zone\":\"us-west-2b\"}"
        }
    ]
}
```
如果输出包含 `NextToken` 字段，可返回更多活动。要获取其他活动，请在后续调用中使用此字段的值和 `--starting-token` 选项，如下所示。  

```
aws autoscaling describe-scaling-activities \
    --starting-token Z3M3LMPEXAMPLE
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[验证自动扩缩组的扩展活动](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-verify-scaling-activity.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeScalingActivities](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-scaling-activities.html)。

### `describe-scaling-process-types`
<a name="auto-scaling_DescribeScalingProcessTypes_cli_topic"></a>

以下代码示例演示了如何使用 `describe-scaling-process-types`。

**AWS CLI**  
**描述可用的流程类型**  
此示例描述可用的流程类型。  

```
aws autoscaling describe-scaling-process-types
```
输出：  

```
{
    "Processes": [
        {
            "ProcessName": "AZRebalance"
        },
        {
            "ProcessName": "AddToLoadBalancer"
        },
        {
            "ProcessName": "AlarmNotification"
        },
        {
            "ProcessName": "HealthCheck"
        },
        {
            "ProcessName": "InstanceRefresh"
        },
        {
            "ProcessName": "Launch"
        },
        {
            "ProcessName": "ReplaceUnhealthy"
        },
        {
            "ProcessName": "ScheduledActions"
        },
        {
            "ProcessName": "Terminate"
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[暂停和恢复扩展流程](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-suspend-resume-processes.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeScalingProcessTypes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-scaling-process-types.html)。

### `describe-scheduled-actions`
<a name="auto-scaling_DescribeScheduledActions_cli_topic"></a>

以下代码示例演示了如何使用 `describe-scheduled-actions`。

**AWS CLI**  
**示例 1：描述所有计划操作**  
此示例描述所有计划操作。  

```
aws autoscaling describe-scheduled-actions
```
输出：  

```
{
    "ScheduledUpdateGroupActions": [
        {
            "AutoScalingGroupName": "my-asg",
            "ScheduledActionName": "my-recurring-action",
            "Recurrence": "30 0 1 1,6,12 *",
            "ScheduledActionARN": "arn:aws:autoscaling:us-west-2:123456789012:scheduledUpdateGroupAction:8e86b655-b2e6-4410-8f29-b4f094d6871c:autoScalingGroupName/my-asg:scheduledActionName/my-recurring-action",
            "StartTime": "2023-12-01T04:00:00Z",
            "Time": "2023-12-01T04:00:00Z",
            "MinSize": 1,
            "MaxSize": 6,
            "DesiredCapacity": 4,
            "TimeZone": "America/New_York"
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[计划扩展](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html)。  
**示例 2：描述指定组的计划操作**  
要描述特定自动扩缩组的计划操作，请使用 `--auto-scaling-group-name` 选项。  

```
aws autoscaling describe-scheduled-actions \
    --auto-scaling-group-name my-asg
```
输出：  

```
{
    "ScheduledUpdateGroupActions": [
        {
            "AutoScalingGroupName": "my-asg",
            "ScheduledActionName": "my-recurring-action",
            "Recurrence": "30 0 1 1,6,12 *",
            "ScheduledActionARN": "arn:aws:autoscaling:us-west-2:123456789012:scheduledUpdateGroupAction:8e86b655-b2e6-4410-8f29-b4f094d6871c:autoScalingGroupName/my-asg:scheduledActionName/my-recurring-action",
            "StartTime": "2023-12-01T04:00:00Z",
            "Time": "2023-12-01T04:00:00Z",
            "MinSize": 1,
            "MaxSize": 6,
            "DesiredCapacity": 4,
            "TimeZone": "America/New_York"
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[计划扩展](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html)。  
**示例 3：描述指定的计划操作**  
要描述特定的计划操作，请使用 `--scheduled-action-names` 选项。  

```
aws autoscaling describe-scheduled-actions \
    --scheduled-action-names my-recurring-action
```
输出：  

```
{
    "ScheduledUpdateGroupActions": [
        {
            "AutoScalingGroupName": "my-asg",
            "ScheduledActionName": "my-recurring-action",
            "Recurrence": "30 0 1 1,6,12 *",
            "ScheduledActionARN": "arn:aws:autoscaling:us-west-2:123456789012:scheduledUpdateGroupAction:8e86b655-b2e6-4410-8f29-b4f094d6871c:autoScalingGroupName/my-asg:scheduledActionName/my-recurring-action",
            "StartTime": "2023-12-01T04:00:00Z",
            "Time": "2023-12-01T04:00:00Z",
            "MinSize": 1,
            "MaxSize": 6,
            "DesiredCapacity": 4,
            "TimeZone": "America/New_York"
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[计划扩展](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html)。  
**示例 4：描述具有指定开始时间的计划操作**  
要描述在特定时间开始的计划操作，请使用 `--start-time` 选项。  

```
aws autoscaling describe-scheduled-actions \
    --start-time "2023-12-01T04:00:00Z"
```
输出：  

```
{
    "ScheduledUpdateGroupActions": [
        {
            "AutoScalingGroupName": "my-asg",
            "ScheduledActionName": "my-recurring-action",
            "Recurrence": "30 0 1 1,6,12 *",
            "ScheduledActionARN": "arn:aws:autoscaling:us-west-2:123456789012:scheduledUpdateGroupAction:8e86b655-b2e6-4410-8f29-b4f094d6871c:autoScalingGroupName/my-asg:scheduledActionName/my-recurring-action",
            "StartTime": "2023-12-01T04:00:00Z",
            "Time": "2023-12-01T04:00:00Z",
            "MinSize": 1,
            "MaxSize": 6,
            "DesiredCapacity": 4,
            "TimeZone": "America/New_York"
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[计划扩展](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html)。  
**示例 5：描述在指定时间结束的计划操作**  
要描述在特定时间结束的计划操作，请使用 `--end-time` 选项。  

```
aws autoscaling describe-scheduled-actions \
    --end-time "2023-12-01T04:00:00Z"
```
输出：  

```
{
    "ScheduledUpdateGroupActions": [
        {
            "AutoScalingGroupName": "my-asg",
            "ScheduledActionName": "my-recurring-action",
            "Recurrence": "30 0 1 1,6,12 *",
            "ScheduledActionARN": "arn:aws:autoscaling:us-west-2:123456789012:scheduledUpdateGroupAction:8e86b655-b2e6-4410-8f29-b4f094d6871c:autoScalingGroupName/my-asg:scheduledActionName/my-recurring-action",
            "StartTime": "2023-12-01T04:00:00Z",
            "Time": "2023-12-01T04:00:00Z",
            "MinSize": 1,
            "MaxSize": 6,
            "DesiredCapacity": 4,
            "TimeZone": "America/New_York"
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[计划扩展](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html)。  
**示例 6：描述指定数量的计划操作**  
要返回特定数量的计划操作，请使用 `--max-items` 选项。  

```
aws autoscaling describe-scheduled-actions \
    --auto-scaling-group-name my-asg \
    --max-items 1
```
输出：  

```
{
    "ScheduledUpdateGroupActions": [
        {
            "AutoScalingGroupName": "my-asg",
            "ScheduledActionName": "my-recurring-action",
            "Recurrence": "30 0 1 1,6,12 *",
            "ScheduledActionARN": "arn:aws:autoscaling:us-west-2:123456789012:scheduledUpdateGroupAction:8e86b655-b2e6-4410-8f29-b4f094d6871c:autoScalingGroupName/my-asg:scheduledActionName/my-recurring-action",
            "StartTime": "2023-12-01T04:00:00Z",
            "Time": "2023-12-01T04:00:00Z",
            "MinSize": 1,
            "MaxSize": 6,
            "DesiredCapacity": 4,
            "TimeZone": "America/New_York"
        }
    ]
}
```
如果输出包含 `NextToken` 字段，可返回更多计划操作。要获取其他计划操作，请在后续调用中使用此字段的值和 `--starting-token` 选项，如下所示。  

```
aws autoscaling describe-scheduled-actions \
    --auto-scaling-group-name my-asg \
    --starting-token Z3M3LMPEXAMPLE
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[计划扩展](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeScheduledActions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-scheduled-actions.html)。

### `describe-tags`
<a name="auto-scaling_DescribeTags_cli_topic"></a>

以下代码示例演示了如何使用 `describe-tags`。

**AWS CLI**  
**描述所有标签**  
此示例描述所有标签。  

```
aws autoscaling describe-tags
```
输出：  

```
{
    "Tags": [
        {
            "ResourceType": "auto-scaling-group",
            "ResourceId": "my-asg",
            "PropagateAtLaunch": true,
            "Value": "Research",
            "Key": "Dept"
        },
        {
            "ResourceType": "auto-scaling-group",
            "ResourceId": "my-asg",
            "PropagateAtLaunch": true,
            "Value": "WebServer",
            "Key": "Role"
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[标记自动扩缩组和实例](https://docs.aws.amazon.com/autoscaling/ec2/userguide/autoscaling-tagging.html)。  
**示例 2：描述指定组的标签**  
要描述特定自动扩缩组的标签，请使用 `--filters` 选项。  

```
aws autoscaling describe-tags --filters Name=auto-scaling-group,Values=my-asg
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[标记自动扩缩组和实例](https://docs.aws.amazon.com/autoscaling/ec2/userguide/autoscaling-tagging.html)。  
**示例 3：描述指定数量的标签**  
要返回特定数量的标签，请使用 `--max-items` 选项。  

```
aws autoscaling describe-tags \
    --max-items 1
```
如果输出包含 `NextToken` 字段，则可返回更多标签。要获取其他标签，请在后续调用中使用此字段的值和 `--starting-token` 选项，如下所示。  

```
aws autoscaling describe-tags \
    --filters Name=auto-scaling-group,Values=my-asg \
    --starting-token Z3M3LMPEXAMPLE
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[标记自动扩缩组和实例](https://docs.aws.amazon.com/autoscaling/ec2/userguide/autoscaling-tagging.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeTags](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-tags.html)。

### `describe-termination-policy-types`
<a name="auto-scaling_DescribeTerminationPolicyTypes_cli_topic"></a>

以下代码示例演示了如何使用 `describe-termination-policy-types`。

**AWS CLI**  
**描述可用的终止策略类型**  
此示例描述可用的终止策略类型。  

```
aws autoscaling describe-termination-policy-types
```
输出：  

```
{
    "TerminationPolicyTypes": [
        "AllocationStrategy",
        "ClosestToNextInstanceHour",
        "Default",
        "NewestInstance",
        "OldestInstance",
        "OldestLaunchConfiguration",
        "OldestLaunchTemplate"
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[控制在横向缩减期间终止哪些自动扩缩实例](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-instance-termination.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeTerminationPolicyTypes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-termination-policy-types.html)。

### `describe-warm-pool`
<a name="auto-scaling_DescribeWarmPool_cli_topic"></a>

以下代码示例演示了如何使用 `describe-warm-pool`。

**AWS CLI**  
**描述热池**  
此示例将描述指定自动扩缩组的热池。  

```
aws autoscaling describe-warm-pool \
    --auto-scaling-group-name my-asg
```
输出：  

```
{
    "WarmPoolConfiguration": {
        "MinSize": 2,
        "PoolState": "Stopped"
    },
    "Instances": [
        {
            "InstanceId": "i-070a5bbc7e7f40dc5",
            "InstanceType": "t2.micro",
            "AvailabilityZone": "us-west-2c",
            "LifecycleState": "Warmed:Pending",
            "HealthStatus": "Healthy",
            "LaunchTemplate": {
                "LaunchTemplateId": "lt-00a731f6e9fa48610",
                "LaunchTemplateName": "my-template-for-auto-scaling",
                "Version": "6"
            }
        },
        {
            "InstanceId": "i-0b52f061814d3bd2d",
            "InstanceType": "t2.micro",
            "AvailabilityZone": "us-west-2b",
            "LifecycleState": "Warmed:Pending",
            "HealthStatus": "Healthy",
            "LaunchTemplate": {
                "LaunchTemplateId": "lt-00a731f6e9fa48610",
                "LaunchTemplateName": "my-template-for-auto-scaling",
                "Version": "6"
            }
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [Amazon EC2 Auto Scaling 的热池](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-warm-pools.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeWarmPool](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/describe-warm-pool.html)。

### `detach-instances`
<a name="auto-scaling_DetachInstances_cli_topic"></a>

以下代码示例演示了如何使用 `detach-instances`。

**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\"}"
        }
    ]
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DetachInstances](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/detach-instances.html)。

### `detach-load-balancer-target-groups`
<a name="auto-scaling_DetachLoadBalancerTargetGroups_cli_topic"></a>

以下代码示例演示了如何使用 `detach-load-balancer-target-groups`。

**AWS CLI**  
**将负载均衡器目标组与自动扩缩组分离**  
此示例将指定的负载均衡器目标组与指定的自动扩缩组分离。  

```
aws autoscaling detach-load-balancer-target-groups \
    --auto-scaling-group-name my-asg \
    --target-group-arns arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067
```
此命令不生成任何输出  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[将负载均衡器挂接到自动扩缩组](https://docs.aws.amazon.com/autoscaling/ec2/userguide/attach-load-balancer-asg.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DetachLoadBalancerTargetGroups](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/detach-load-balancer-target-groups.html)。

### `detach-load-balancers`
<a name="auto-scaling_DetachLoadBalancers_cli_topic"></a>

以下代码示例演示了如何使用 `detach-load-balancers`。

**AWS CLI**  
**将经典负载均衡器与自动扩缩组分离**  
此示例将指定的经典负载均衡器与指定的自动扩缩组分离。  

```
aws autoscaling detach-load-balancers \
    --load-balancer-names my-load-balancer \
    --auto-scaling-group-name my-asg
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[将负载均衡器挂接到自动扩缩组](https://docs.aws.amazon.com/autoscaling/ec2/userguide/attach-load-balancer-asg.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DetachLoadBalancers](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/detach-load-balancers.html)。

### `disable-metrics-collection`
<a name="auto-scaling_DisableMetricsCollection_cli_topic"></a>

以下代码示例演示了如何使用 `disable-metrics-collection`。

**AWS CLI**  
**禁用自动扩缩组指标收集**  
此示例禁用指定自动扩缩组的 `GroupDesiredCapacity` 指标的收集。  

```
aws autoscaling disable-metrics-collection \
    --auto-scaling-group-name my-asg \
    --metrics GroupDesiredCapacity
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[监控自动扩缩组和实例的 CloudWatch 指标](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-instance-monitoring.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DisableMetricsCollection](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/disable-metrics-collection.html)。

### `enable-metrics-collection`
<a name="auto-scaling_EnableMetricsCollection_cli_topic"></a>

以下代码示例演示了如何使用 `enable-metrics-collection`。

**AWS CLI**  
**示例 1：启用自动扩缩组的指标收集**  
此示例启用指定自动扩缩组的数据收集。  

```
aws autoscaling enable-metrics-collection \
    --auto-scaling-group-name my-asg \
    --granularity "1Minute"
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[监控自动扩缩组和实例的 CloudWatch 指标](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-instance-monitoring.html)。  
**示例 2：收集自动扩缩组指定指标的相关数据**  
要收集特定指标的相关数据，请使用 `--metrics` 选项。  

```
aws autoscaling enable-metrics-collection \
    --auto-scaling-group-name my-asg \
    --metrics GroupDesiredCapacity --granularity "1Minute"
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[监控自动扩缩组和实例的 CloudWatch 指标](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-instance-monitoring.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [EnableMetricsCollection](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/enable-metrics-collection.html)。

### `enter-standby`
<a name="auto-scaling_EnterStandby_cli_topic"></a>

以下代码示例演示了如何使用 `enter-standby`。

**AWS CLI**  
**将实例移入备用模式**  
此示例将指定实例置于备用模式。这对于更新当前正在使用的实例或对其进行问题排查非常有用。  

```
aws autoscaling enter-standby \
    --instance-ids i-061c63c5eb45f0416 \
    --auto-scaling-group-name my-asg \
    --should-decrement-desired-capacity
```
输出：  

```
{
    "Activities": [
        {
            "ActivityId": "ffa056b4-6ed3-41ba-ae7c-249dfae6eba1",
            "AutoScalingGroupName": "my-asg",
            "Description": "Moving EC2 instance to Standby: i-061c63c5eb45f0416",
            "Cause": "At 2020-10-31T20:31:00Z instance i-061c63c5eb45f0416 was moved to standby in response to a user request, shrinking the capacity from 1 to 0.",
            "StartTime": "2020-10-31T20:31:00.949Z",
            "StatusCode": "InProgress",
            "Progress": 50,
            "Details": "{\"Subnet ID\":\"subnet-6194ea3b\",\"Availability Zone\":\"us-west-2c\"}"
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [Amazon EC2 Auto Scaling 实例生命周期](https://docs.aws.amazon.com/autoscaling/ec2/userguide/detach-instance-asg.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [EnterStandby](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/enter-standby.html)。

### `execute-policy`
<a name="auto-scaling_ExecutePolicy_cli_topic"></a>

以下代码示例演示了如何使用 `execute-policy`。

**AWS CLI**  
**执行扩展策略**  
此示例将对指定的自动扩缩组执行名为 `my-step-scale-out-policy` 的扩展策略。  

```
aws autoscaling execute-policy \
    --auto-scaling-group-name my-asg \
    --policy-name  my-step-scale-out-policy \
    --metric-value 95 \
    --breach-threshold 80
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[步进和简单扩展策略](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scaling-simple-step.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ExecutePolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/execute-policy.html)。

### `exit-standby`
<a name="auto-scaling_ExitStandby_cli_topic"></a>

以下代码示例演示了如何使用 `exit-standby`。

**AWS CLI**  
**将实例移出备用模式**  
此示例将指定的实例移出备用模式。  

```
aws autoscaling exit-standby \
    --instance-ids i-061c63c5eb45f0416 \
    --auto-scaling-group-name my-asg
```
输出：  

```
{
    "Activities": [
        {
            "ActivityId": "142928e1-a2dc-453a-9b24-b85ad6735928",
            "AutoScalingGroupName": "my-asg",
            "Description": "Moving EC2 instance out of Standby: i-061c63c5eb45f0416",
            "Cause": "At 2020-10-31T20:32:50Z instance i-061c63c5eb45f0416 was moved out of standby in response to a user request, increasing the capacity from 0 to 1.",
            "StartTime": "2020-10-31T20:32:50.222Z",
            "StatusCode": "PreInService",
            "Progress": 30,
            "Details": "{\"Subnet ID\":\"subnet-6194ea3b\",\"Availability Zone\":\"us-west-2c\"}"
        }
    ]
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[临时从自动扩缩组中移除实例](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-enter-exit-standby.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ExitStandby](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/exit-standby.html)。

### `put-lifecycle-hook`
<a name="auto-scaling_PutLifecycleHook_cli_topic"></a>

以下代码示例演示了如何使用 `put-lifecycle-hook`。

**AWS CLI**  
**示例 1：创建生命周期挂钩**  
此示例创建一个生命周期挂钩，该挂钩将在任何新启动的实例上调用，超时时间为 4800 秒。这对于在用户数据脚本完成之前保持实例处于等待状态，或使用 EventBridge 调用 AWS Lambda 函数很有用。  

```
aws autoscaling put-lifecycle-hook \
    --auto-scaling-group-name my-asg \
    --lifecycle-hook-name my-launch-hook \
    --lifecycle-transition autoscaling:EC2_INSTANCE_LAUNCHING \
    --heartbeat-timeout 4800
```
此命令不生成任何输出。如果已存在同名的生命周期挂钩，则该挂钩将被新的生命周期挂钩覆盖。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [Amazon EC2 Auto Scaling 生命周期挂钩](https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html)。  
**示例 2：发送 Amazon SNS 电子邮件以通知您实例状态转换**  
此示例创建一个包含 Amazon SNS 主题和 IAM 角色的生命周期挂钩，用于在实例启动时接收通知。  

```
aws autoscaling put-lifecycle-hook \
    --auto-scaling-group-name my-asg \
    --lifecycle-hook-name my-launch-hook \
    --lifecycle-transition autoscaling:EC2_INSTANCE_LAUNCHING \
    --notification-target-arn arn:aws:sns:us-west-2:123456789012:my-sns-topic \
    --role-arn arn:aws:iam::123456789012:role/my-auto-scaling-role
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [Amazon EC2 Auto Scaling 生命周期挂钩](https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html)。  
**示例 3：向 Amazon SQS 队列发布消息**  
此示例创建一个生命周期挂钩，该挂钩将包含元数据的消息发布到指定的 Amazon SQS 队列。  

```
aws autoscaling put-lifecycle-hook \
    --auto-scaling-group-name my-asg \
    --lifecycle-hook-name my-launch-hook \
    --lifecycle-transition autoscaling:EC2_INSTANCE_LAUNCHING \
    --notification-target-arn arn:aws:sqs:us-west-2:123456789012:my-sqs-queue \
    --role-arn arn:aws:iam::123456789012:role/my-notification-role \
    --notification-metadata "SQS message metadata"
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [Amazon EC2 Auto Scaling 生命周期挂钩](https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [PutLifecycleHook](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/put-lifecycle-hook.html)。

### `put-notification-configuration`
<a name="auto-scaling_PutNotificationConfiguration_cli_topic"></a>

以下代码示例演示了如何使用 `put-notification-configuration`。

**AWS CLI**  
**添加通知**  
此示例将指定的通知添加到指定的自动扩缩组。  

```
aws autoscaling put-notification-configuration \
    --auto-scaling-group-name my-asg \
    --topic-arn arn:aws:sns:us-west-2:123456789012:my-sns-topic \
    --notification-type autoscaling:TEST_NOTIFICATION
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[在自动扩缩组扩展时获取 Amazon SNS 通知](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ASGettingNotifications.html#as-configure-asg-for-sns)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [PutNotificationConfiguration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/put-notification-configuration.html)。

### `put-scaling-policy`
<a name="auto-scaling_PutScalingPolicy_cli_topic"></a>

以下代码示例演示了如何使用 `put-scaling-policy`。

**AWS CLI**  
**向自动扩缩组添加目标跟踪扩展策略**  
以下 `put-scaling-policy` 示例将目标跟踪扩展策略应用到指定的自动扩缩组。输出包含代表您创建的两个 CloudWatch 警报的 ARN 和名称。如果已存在同名扩缩策略，则该扩展策略将被新扩展策略覆盖。  

```
aws autoscaling put-scaling-policy --auto-scaling-group-name my-asg \
  --policy-name alb1000-target-tracking-scaling-policy \
  --policy-type TargetTrackingScaling \
  --target-tracking-configuration file://config.json
```
 的内容`config.json`：  

```
{
     "TargetValue": 1000.0,
     "PredefinedMetricSpecification": {
          "PredefinedMetricType": "ALBRequestCountPerTarget",
          "ResourceLabel": "app/my-alb/778d41231b141a0f/targetgroup/my-alb-target-group/943f017f100becff"
     }
}
```
输出：  

```
{
     "PolicyARN": "arn:aws:autoscaling:region:account-id:scalingPolicy:228f02c2-c665-4bfd-aaac-8b04080bea3c:autoScalingGroupName/my-asg:policyName/alb1000-target-tracking-scaling-policy",
     "Alarms": [
         {
             "AlarmARN": "arn:aws:cloudwatch:region:account-id:alarm:TargetTracking-my-asg-AlarmHigh-fc0e4183-23ac-497e-9992-691c9980c38e",
             "AlarmName": "TargetTracking-my-asg-AlarmHigh-fc0e4183-23ac-497e-9992-691c9980c38e"
         },
         {
             "AlarmARN": "arn:aws:cloudwatch:region:account-id:alarm:TargetTracking-my-asg-AlarmLow-61a39305-ed0c-47af-bd9e-471a352ee1a2",
             "AlarmName": "TargetTracking-my-asg-AlarmLow-61a39305-ed0c-47af-bd9e-471a352ee1a2"
         }
     ]
 }
```
有关更多示例，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [AWS 命令行界面（AWS CLI）的扩展策略示例](https://docs.aws.amazon.com/autoscaling/ec2/userguide/examples-scaling-policies.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [PutScalingPolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/put-scaling-policy.html)。

### `put-scheduled-update-group-action`
<a name="auto-scaling_PutScheduledUpdateGroupAction_cli_topic"></a>

以下代码示例演示了如何使用 `put-scheduled-update-group-action`。

**AWS CLI**  
**示例 1：向自动扩缩组添加计划操作**  
此示例将指定的计划操作添加到指定的自动扩缩组。  

```
aws autoscaling put-scheduled-update-group-action \
    --auto-scaling-group-name my-asg \
    --scheduled-action-name my-scheduled-action \
    --start-time "2023-05-12T08:00:00Z" \
    --min-size 2 \
    --max-size 6 \
    --desired-capacity 4
```
此命令不生成任何输出。如果已存在同名的计划操作，则该计划操作将被新计划操作覆盖。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[计划扩展](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html)。  
**示例 2：指定周期性计划**  
此示例创建一个计划操作，以按计划在每年一月、六月和十二月的第一天 00:30 执行的周期性计划进行扩展。  

```
aws autoscaling put-scheduled-update-group-action \
    --auto-scaling-group-name my-asg \
    --scheduled-action-name my-recurring-action \
    --recurrence "30 0 1 1,6,12 *" \
    --min-size 2 \
    --max-size 6 \
    --desired-capacity 4
```
此命令不生成任何输出。如果已存在同名的计划操作，则该计划操作将被新计划操作覆盖。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[计划扩展](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [PutScheduledUpdateGroupAction](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/put-scheduled-update-group-action.html)。

### `put-warm-pool`
<a name="auto-scaling_PutWarmPool_cli_topic"></a>

以下代码示例演示了如何使用 `put-warm-pool`。

**AWS CLI**  
**创建热池**  
以下示例为指定的自动扩缩组创建热池。  

```
aws autoscaling put-warm-pool \
    --auto-scaling-group-name my-asg \
    --min-size 2
```
此命令不生成任何输出。如果已经存在热池，则会对其进行更新。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [Amazon EC2 Auto Scaling 的热池](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-warm-pools.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [PutWarmPool](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/put-warm-pool.html)。

### `record-lifecycle-action-heartbeat`
<a name="auto-scaling_RecordLifecycleActionHeartbeat_cli_topic"></a>

以下代码示例演示了如何使用 `record-lifecycle-action-heartbeat`。

**AWS CLI**  
**记录生命周期操作心跳**  
此示例记录生命周期操作心跳，以使实例保持待处理状态。  

```
aws autoscaling record-lifecycle-action-heartbeat \
    --lifecycle-hook-name my-launch-hook \
    --auto-scaling-group-name my-asg \
    --lifecycle-action-token bcd2f1b8-9a78-44d3-8a7a-4dd07d7cf635
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [Amazon EC2 Auto Scaling 生命周期挂钩](https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [RecordLifecycleActionHeartbeat](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/record-lifecycle-action-heartbeat.html)。

### `resume-processes`
<a name="auto-scaling_ResumeProcesses_cli_topic"></a>

以下代码示例演示了如何使用 `resume-processes`。

**AWS CLI**  
**恢复暂停的流程**  
此示例恢复指定自动扩缩组的指定暂停扩展流程。  

```
aws autoscaling resume-processes \
    --auto-scaling-group-name my-asg \
    --scaling-processes AlarmNotification
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[暂停和恢复扩展流程](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-suspend-resume-processes.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ResumeProcesses](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/resume-processes.html)。

### `rollback-instance-refresh`
<a name="auto-scaling_RollbackInstanceRefresh_cli_topic"></a>

以下代码示例演示了如何使用 `rollback-instance-refresh`。

**AWS CLI**  
**回滚实例刷新**  
以下 `rollback-instance-refresh` 示例回滚指定自动扩缩组正在进行的实例刷新。  

```
aws autoscaling rollback-instance-refresh \
    --auto-scaling-group-name my-asg
```
输出：  

```
{
    "InstanceRefreshId": "08b91cf7-8fa6-48af-b6a6-d227f40f1b9b"
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[通过回滚撤消更改](https://docs.aws.amazon.com/autoscaling/ec2/userguide/instance-refresh-rollback.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [RollbackInstanceRefresh](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/rollback-instance-refresh.html)。

### `set-desired-capacity`
<a name="auto-scaling_SetDesiredCapacity_cli_topic"></a>

以下代码示例演示了如何使用 `set-desired-capacity`。

**AWS CLI**  
**为自动扩缩组设置所需容量**  
此示例为指定的自动扩缩组设置所需容量。  

```
aws autoscaling set-desired-capacity \
    --auto-scaling-group-name my-asg \
    --desired-capacity 2 \
    --honor-cooldown
```
如果成功，该命令将返回到提示符。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [SetDesiredCapacity](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/set-desired-capacity.html)。

### `set-instance-health`
<a name="auto-scaling_SetInstanceHealth_cli_topic"></a>

以下代码示例演示了如何使用 `set-instance-health`。

**AWS CLI**  
**设置实例的运行状况**  
此示例将指定实例的运行状况设置为 `Unhealthy`。  

```
aws autoscaling set-instance-health \
    --instance-id i-061c63c5eb45f0416 \
    --health-status Unhealthy
```
此命令不生成任何输出。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [SetInstanceHealth](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/set-instance-health.html)。

### `set-instance-protection`
<a name="auto-scaling_SetInstanceProtection_cli_topic"></a>

以下代码示例演示了如何使用 `set-instance-protection`。

**AWS CLI**  
**示例 1：启用实例的实例保护设置**  
此示例启用对指定实例的实例保护。  

```
aws autoscaling set-instance-protection \
    --instance-ids i-061c63c5eb45f0416 \
    --auto-scaling-group-name my-asg --protected-from-scale-in
```
此命令不生成任何输出。  
**示例 2：禁用实例的实例保护设置**  
此示例禁用对指定实例的实例保护。  

```
aws autoscaling set-instance-protection \
    --instance-ids i-061c63c5eb45f0416 \
    --auto-scaling-group-name my-asg \
    --no-protected-from-scale-in
```
此命令不生成任何输出。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [SetInstanceProtection](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/set-instance-protection.html)。

### `start-instance-refresh`
<a name="auto-scaling_StartInstanceRefresh_cli_topic"></a>

以下代码示例演示了如何使用 `start-instance-refresh`。

**AWS CLI**  
**示例 1：使用命令行参数启动实例刷新**  
以下 `start-instance-refresh` 示例使用命令行参数启动实例刷新。可选的 `preferences` 参数指定 `InstanceWarmup` 为 `60` 秒，`MinHealthyPercentage` 为 `50` %。  

```
aws autoscaling start-instance-refresh \
    --auto-scaling-group-name my-asg \
    --preferences '{"InstanceWarmup": 60, "MinHealthyPercentage": 50}'
```
输出：  

```
{
    "InstanceRefreshId": "08b91cf7-8fa6-48af-b6a6-d227f40f1b9b"
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[启动实例刷新](https://docs.aws.amazon.com/en_us/autoscaling/ec2/userguide/start-instance-refresh.html)。  
**示例 2：使用 JSON 文件启动实例刷新**  
以下 `start-instance-refresh` 示例使用 JSON 文件启动实例刷新。您可以指定自动扩缩组，并在 JSON 文件中定义所需的配置和首选项，如以下示例所示。  

```
aws autoscaling start-instance-refresh \
    --cli-input-json file://config.json
```
 的内容`config.json`：  

```
{
    "AutoScalingGroupName": "my-asg",
    "DesiredConfiguration": {
        "LaunchTemplate": {
            "LaunchTemplateId": "lt-068f72b729example",
            "Version": "$Default"
        }
    },
    "Preferences": {
        "InstanceWarmup": 60,
        "MinHealthyPercentage": 50,
        "AutoRollback": true,
        "ScaleInProtectedInstances": Ignore,
        "StandbyInstances": Terminate
    }
}
```
输出：  

```
{
    "InstanceRefreshId": "08b91cf7-8fa6-48af-b6a6-d227f40f1b9b"
}
```
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[启动实例刷新](https://docs.aws.amazon.com/en_us/autoscaling/ec2/userguide/start-instance-refresh.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [StartInstanceRefresh](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/start-instance-refresh.html)。

### `suspend-processes`
<a name="auto-scaling_SuspendProcesses_cli_topic"></a>

以下代码示例演示了如何使用 `suspend-processes`。

**AWS CLI**  
**暂停自动扩缩流程**  
此示例暂停指定自动扩缩组的指定扩展流程。  

```
aws autoscaling suspend-processes \
    --auto-scaling-group-name my-asg \
    --scaling-processes AlarmNotification
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[暂停和恢复扩展流程](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-suspend-resume-processes.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [SuspendProcesses](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/suspend-processes.html)。

### `terminate-instance-in-auto-scaling-group`
<a name="auto-scaling_TerminateInstanceInAutoScalingGroup_cli_topic"></a>

以下代码示例演示了如何使用 `terminate-instance-in-auto-scaling-group`。

**AWS CLI**  
**终止自动扩缩组中的实例**  
此示例在不更新指定自动扩缩组大小的情况下终止该组中的指定实例。Amazon EC2 Auto Scaling 会在指定实例终止后启动替代实例。  

```
aws autoscaling terminate-instance-in-auto-scaling-group \
    --instance-id i-061c63c5eb45f0416 \
    --no-should-decrement-desired-capacity
```
输出：  

```
{
    "Activities": [
        {
            "ActivityId": "8c35d601-793c-400c-fcd0-f64a27530df7",
            "AutoScalingGroupName": "my-asg",
            "Description": "Terminating EC2 instance: i-061c63c5eb45f0416",
            "Cause": "",
            "StartTime": "2020-10-31T20:34:25.680Z",
            "StatusCode": "InProgress",
            "Progress": 0,
            "Details": "{\"Subnet ID\":\"subnet-6194ea3b\",\"Availability Zone\":\"us-west-2c\"}"
        }
    ]
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [TerminateInstanceInAutoScalingGroup](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/terminate-instance-in-auto-scaling-group.html)。

### `update-auto-scaling-group`
<a name="auto-scaling_UpdateAutoScalingGroup_cli_topic"></a>

以下代码示例演示了如何使用 `update-auto-scaling-group`。

**AWS CLI**  
**示例 1：更新自动扩缩组的大小限制**  
该示例更新指定的自动扩缩组，该组的最小大小为 1，最大大小为 10。  

```
aws autoscaling update-auto-scaling-group \
    --auto-scaling-group-name my-asg \
    --min-size 2 \
    --max-size 10
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[设置自动扩缩组的容量限制](https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-capacity-limits.html)。  
**示例 2：添加 Elastic Load Balancing 运行状况检查并指定要使用的可用区和子网**  
此示例更新指定的自动扩缩组以添加 Elastic Load Balancing 运行状况检查。此命令还会使用多个可用区中的子网 ID 列表更新 `--vpc-zone-identifier` 的值。  

```
aws autoscaling update-auto-scaling-group \
    --auto-scaling-group-name my-asg \
    --health-check-type ELB \
    --health-check-grace-period 600 \
    --vpc-zone-identifier "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782"
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的 [Elastic Load Balancing 和 Amazon EC2 Auto Scaling](https://docs.aws.amazon.com/autoscaling/ec2/userguide/autoscaling-load-balancer.html)。  
**示例 3：更新置放群组和终止策略**  
此示例更新要使用的置放群组和终止策略。  

```
aws autoscaling update-auto-scaling-group \
    --auto-scaling-group-name my-asg \
    --placement-group my-placement-group \
    --termination-policies "OldestInstance"
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[自动扩缩组](https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html)。  
**示例 4：使用最新版本的启动模板**  
此示例将指定的自动扩缩组更新为使用最新版本的指定启动模板。  

```
aws autoscaling update-auto-scaling-group \
    --auto-scaling-group-name my-asg \
    --launch-template LaunchTemplateId=lt-1234567890abcde12,Version='$Latest'
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[启动模板](https://docs.aws.amazon.com/autoscaling/ec2/userguide/LaunchTemplates.html)。  
**示例 5：使用特定版本的启动模板**  
此示例将指定的自动扩缩组更新为使用特定版本的启动模板，而不是最新或默认版本。  

```
aws autoscaling update-auto-scaling-group \
    --auto-scaling-group-name my-asg \
    --launch-template LaunchTemplateName=my-template-for-auto-scaling,Version='2'
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[启动模板](https://docs.aws.amazon.com/autoscaling/ec2/userguide/LaunchTemplates.html)。  
**示例 6：定义混合实例策略并启用容量再平衡**  
此示例将指定的自动扩缩组更新为使用混合实例策略并启用容量再平衡。此结构允许您指定具有竞价和按需容量的组，并针对不同的架构使用不同的启动模板。  

```
aws autoscaling update-auto-scaling-group \
    --cli-input-json file://~/config.json
```
 的内容`config.json`：  

```
{
    "AutoScalingGroupName": "my-asg",
    "CapacityRebalance": true,
    "MixedInstancesPolicy": {
        "LaunchTemplate": {
            "LaunchTemplateSpecification": {
                "LaunchTemplateName": "my-launch-template-for-x86",
                "Version": "$Latest"
            },
            "Overrides": [
                {
                    "InstanceType": "c6g.large",
                    "LaunchTemplateSpecification": {
                        "LaunchTemplateName": "my-launch-template-for-arm",
                        "Version": "$Latest"
                    }
                },
                {
                    "InstanceType": "c5.large"
                },
                {
                    "InstanceType": "c5a.large"
                }
            ]
        },
        "InstancesDistribution": {
            "OnDemandPercentageAboveBaseCapacity": 50,
            "SpotAllocationStrategy": "capacity-optimized"
        }
    }
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon EC2 Auto Scaling 用户指南》**中的[具有多个实例类型和购买选项的自动扩缩组](https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-purchase-options.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdateAutoScalingGroup](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling/update-auto-scaling-group.html)。