暂停和恢复 Application Auto Scaling 扩缩 - Application Auto Scaling
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

暂停和恢复 Application Auto Scaling 扩缩

本主题说明如何暂停然后恢复应用程序中可扩展目标的一个或多个扩展活动。暂停-恢复功能用于临时暂停由您的扩展策略和计划操作触发的扩展活动。暂停-恢复功能非常有用,例如,当您更改或调查配置问题时,不希望自动扩展潜在产生干扰。您可以保留您的扩展策略和计划操作,在您准备就绪时,可以恢复扩展活动。

在随后的示例 CLI 命令中,您可在 config.json 文件中传递 JSON 格式的参数。您还可以通过使用引号将 JSON 数据结构括起来,在命令行上传递这些参数。有关更多信息,请参阅 Amazon Command Line Interface 用户指南中的在 Amazon CLI 中将引号和字符串结合使用

注意

有关在 Amazon ECS 部署过程中暂停扩展流程的说明,请参阅以下文档:

Amazon 弹性容器服务开发者指南中的服务自动扩展和部署

扩缩活动

Application Auto Scaling 支持将以下扩缩活动置于暂停状态:

  • 由扩展策略触发的所有缩减活动。

  • 由扩展策略触发的所有横向扩展活动。

  • 涉及计划操作的所有扩展活动。

以下描述说明了暂停各个扩展活动时会发生什么。每个扩展活动都可以单独暂停和恢复。根据暂停扩展活动的原因,您可能需要一起暂停多个扩展活动。

DynamicScalingInSuspended

  • 在触发目标跟踪扩缩策略或分步扩缩策略时,Application Auto Scaling 不会删除容量。这使您可以暂时禁用与扩展策略关联的缩减活动,而不删除扩展策略或其关联的 CloudWatch 警报。当您恢复横向缩减时,Application Auto Scaling 会评估具有当前违反的警报阈值的策略。

DynamicScalingOutSuspended

  • 在触发目标跟踪扩缩策略或分步扩缩策略时,Application Auto Scaling 不会增加容量。这使您可以暂时禁用与扩展策略关联的横向扩展活动,而不删除扩展策略或其关联的 CloudWatch 警报。当您恢复横向扩展时,Application Auto Scaling 会评估具有当前违反的警报阈值的策略。

ScheduledScalingSuspended

  • 在暂停期间,Application Auto Scaling 不启动计划要运行的扩缩操作。当您恢复计划的扩缩时,Application Auto Scaling 仅评估尚未经过执行时间的计划操作。

暂停和恢复扩展活动

您可以暂停和恢复 Application Auto Scaling 可扩展目标的单个或所有扩缩活动。

注意

为简洁起见,这些示例说明了如何暂停和恢复 DynamoDB 表的扩缩。要指定不同的可扩展目标,请在 --service-namespace 中指定其命名空间,在 --scalable-dimension 中指定其可扩展维度,并在 --resource-id 中指定其资源 ID。有关每项服务的更多信息和示例,请参阅 可以与 Application Auto Scaling 一起使用的 Amazon 服务 中的主题。

暂停扩展活动

打开一个命令行窗口,然后使用 register-scalable-target 命令和 --suspended-state 选项,如下所示。

Linux、macOS 或 Unix

aws application-autoscaling register-scalable-target --service-namespace dynamodb \ --scalable-dimension dynamodb:table:ReadCapacityUnits --resource-id table/my-table \ --suspended-state file://config.json

Windows

aws application-autoscaling register-scalable-target --service-namespace dynamodb --scalable-dimension dynamodb:table:ReadCapacityUnits --resource-id table/my-table --suspended-state file://config.json

如果成功,该命令会返回可扩展目标的 ARN。

{ "ScalableTargetARN": "arn:aws:application-autoscaling:region:account-id:scalable-target/1234abcd56ab78cd901ef1234567890ab123" }

要仅暂停某个扩展策略触发的缩减活动,请在 config.json 中指定以下内容。

{ "DynamicScalingInSuspended":true }

要仅暂停某个扩展策略触发的横向扩展活动,请在 config.json 中指定以下内容。

{ "DynamicScalingOutSuspended":true }

要仅暂停涉及计划操作的扩展活动,请在 config.json 中指定以下内容。

{ "ScheduledScalingSuspended":true }
暂停所有扩展活动

register-scalable-target 命令与 --suspended-state 选项一起使用,如下所示。

Linux、macOS 或 Unix

aws application-autoscaling register-scalable-target --service-namespace dynamodb \ --scalable-dimension dynamodb:table:ReadCapacityUnits --resource-id table/my-table \ --suspended-state file://config.json

Windows

aws application-autoscaling register-scalable-target --service-namespace dynamodb --scalable-dimension dynamodb:table:ReadCapacityUnits --resource-id table/my-table --suspended-state file://config.json

此示例假定文件 config.json 包含以下 JSON 格式的参数。

{ "DynamicScalingInSuspended":true, "DynamicScalingOutSuspended":true, "ScheduledScalingSuspended":true }

如果成功,该命令会返回可扩展目标的 ARN。

{ "ScalableTargetARN": "arn:aws:application-autoscaling:region:account-id:scalable-target/1234abcd56ab78cd901ef1234567890ab123" }

查看暂停的扩缩活动

使用 describe-scalable-targets 命令可确定可扩展目标处于暂停状态的扩展活动。

Linux、macOS 或 Unix

aws application-autoscaling describe-scalable-targets --service-namespace dynamodb \ --scalable-dimension dynamodb:table:ReadCapacityUnits --resource-id table/my-table

Windows

aws application-autoscaling describe-scalable-targets --service-namespace dynamodb --scalable-dimension dynamodb:table:ReadCapacityUnits --resource-id table/my-table

下面是示例输出。

{ "ScalableTargets": [ { "ServiceNamespace": "dynamodb", "ScalableDimension": "dynamodb:table:ReadCapacityUnits", "ResourceId": "table/my-table", "MinCapacity": 1, "MaxCapacity": 20, "SuspendedState": { "DynamicScalingOutSuspended": true, "DynamicScalingInSuspended": true, "ScheduledScalingSuspended": true }, "CreationTime": 1558125758.957, "RoleARN": "arn:aws:iam::123456789012:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable" } ] }

恢复扩缩活动

当您准备好恢复扩展活动时,可以使用 register-scalable-target 命令恢复它。

以下示例命令恢复指定的可扩展目标的所有扩展活动。

Linux、macOS 或 Unix

aws application-autoscaling register-scalable-target --service-namespace dynamodb \ --scalable-dimension dynamodb:table:ReadCapacityUnits --resource-id table/my-table \ --suspended-state file://config.json

Windows

aws application-autoscaling register-scalable-target --service-namespace dynamodb --scalable-dimension dynamodb:table:ReadCapacityUnits --resource-id table/my-table --suspended-state file://config.json

此示例假定文件 config.json 包含以下 JSON 格式的参数。

{ "DynamicScalingInSuspended":false, "DynamicScalingOutSuspended":false, "ScheduledScalingSuspended":false }

如果成功,该命令会返回可扩展目标的 ARN。

{ "ScalableTargetARN": "arn:aws:application-autoscaling:region:account-id:scalable-target/1234abcd56ab78cd901ef1234567890ab123" }