Application Auto Scaling 的计划操作示例 - Application Auto Scaling
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

Application Auto Scaling 的计划操作示例

以下示例说明如何使用该 Amazon CLI put-scheduled-action命令创建计划操作。当您指定新容量时,可指定最小容量和/或最大容量。

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

使用时 Amazon CLI,请记住您的命令在 Amazon Web Services 区域 配置文件中运行。如果您想要在不同的区域中运行命令,可以为配置文件更改默认区域,或者与命令一起使用 --region 参数。

创建仅发生一次的计划操作

要在指定的日期和时间仅弹性伸缩可扩展目标一次,请使用 --schedule "at(yyyy-mm-ddThh:mm:ss)" 选项。

例 示例:仅向外扩展一次

以下是创建计划操作以在特定日期和时间横向扩展容量的示例。

在为 --schedule 指定的日期和时间(UTC 时间 2021 年 3 月 31 日晚上 10:00),如果为 MinCapacity 指定的值高于当前容量,则 Application Auto Scaling 将横向扩展到 MinCapacity

Linux、macOS 或 Unix

aws application-autoscaling put-scheduled-action --service-namespace custom-resource \ --scalable-dimension custom-resource:ResourceType:Property \ --resource-id file://~/custom-resource-id.txt \ --scheduled-action-name scale-out \ --schedule "at(2021-03-31T22:00:00)" \ --scalable-target-action MinCapacity=3

Windows

aws application-autoscaling put-scheduled-action --service-namespace custom-resource --scalable-dimension custom-resource:ResourceType:Property --resource-id file://~/custom-resource-id.txt --scheduled-action-name scale-out --schedule "at(2021-03-31T22:00:00)" --scalable-target-action MinCapacity=3
注意

运行此计划操作时,如果最大容量小于为最小容量指定的值,则必须指定新的最小容量和最大容量,而不仅仅是最小容量。

例 示例:仅向内扩展一次

以下是创建计划操作以在特定日期和时间横向缩减容量的示例。

在为 --schedule 指定的日期和时间(UTC 时间 2021 年 3 月 31 日晚上 10:30),如果为 MaxCapacity 指定的值低于当前容量,则 Application Auto Scaling 将横向缩减到 MaxCapacity

Linux、macOS 或 Unix

aws application-autoscaling put-scheduled-action --service-namespace custom-resource \ --scalable-dimension custom-resource:ResourceType:Property \ --resource-id file://~/custom-resource-id.txt \ --scheduled-action-name scale-in \ --schedule "at(2021-03-31T22:30:00)" \ --scalable-target-action MinCapacity=0,MaxCapacity=0

Windows

aws application-autoscaling put-scheduled-action --service-namespace custom-resource --scalable-dimension custom-resource:ResourceType:Property --resource-id file://~/custom-resource-id.txt --scheduled-action-name scale-in --schedule "at(2021-03-31T22:30:00)" --scalable-target-action MinCapacity=0,MaxCapacity=0

创建按重复间隔运行的计划操作

要按重复间隔计划扩缩,请使用 --schedule "rate(value unit)" 选项。该值必须为正整数。单位可以是 minuteminuteshourhoursdaydays。有关更多信息,请参阅 Amazon Ev CloudWatch ents 用户指南中的费率表达式

以下是使用 rate 表达式的计划操作的示例。

根据指定的计划(从 UTC 时间 2021 年 1 月 30 日中午 12:00 PM 开始,到 UTC 时间 2021 年 1 月 31 日晚上 10:00 结束,每 5 个小时一次),如果为 MinCapacity 指定的值高于当前容量,则 Application Auto Scaling 横向扩展到 MinCapacity。如果为 MaxCapacity 指定的值低于当前容量,则 Application Auto Scaling 将横向缩减到 MaxCapacity

Linux、macOS 或 Unix

aws application-autoscaling put-scheduled-action --service-namespace ecs \ --scalable-dimension ecs:service:DesiredCount \ --resource-id service/my-cluster/my-service \ --scheduled-action-name my-recurring-action \ --schedule "rate(5 hours)" \ --start-time 2021-01-30T12:00:00 \ --end-time 2021-01-31T22:00:00 \ --scalable-target-action MinCapacity=3,MaxCapacity=10

Windows

aws application-autoscaling put-scheduled-action --service-namespace ecs --scalable-dimension ecs:service:DesiredCount --resource-id service/my-cluster/my-service --scheduled-action-name my-recurring-action --schedule "rate(5 hours)" --start-time 2021-01-30T12:00:00 --end-time 2021-01-31T22:00:00 --scalable-target-action MinCapacity=3,MaxCapacity=10

创建按重复计划运行的计划操作

要按重复计划来计划扩缩,请使用 --schedule "cron(fields)" 选项。有关更多信息,请参阅 使用 cron 表达式安排重复发生的扩缩操作

以下是使用 cron 表达式的计划操作的示例。

根据指定的计划(UTC 时间每天上午 9:00),如果为 MinCapacity 指定的值高于当前容量,则 Application Auto Scaling 将横向扩展到 MinCapacity。如果为 MaxCapacity 指定的值低于当前容量,则 Application Auto Scaling 将横向缩减到 MaxCapacity

Linux、macOS 或 Unix

aws application-autoscaling put-scheduled-action --service-namespace appstream \ --scalable-dimension appstream:fleet:DesiredCapacity \ --resource-id fleet/sample-fleet \ --scheduled-action-name my-recurring-action \ --schedule "cron(0 9 * * ? *)" \ --scalable-target-action MinCapacity=10,MaxCapacity=50

Windows

aws application-autoscaling put-scheduled-action --service-namespace appstream --scalable-dimension appstream:fleet:DesiredCapacity --resource-id fleet/sample-fleet --scheduled-action-name my-recurring-action --schedule "cron(0 9 * * ? *)" --scalable-target-action MinCapacity=10,MaxCapacity=50

创建指定时区的一次性计划操作

默认情况下,计划操作设置为 UTC 时区。要指定不同的时区,请包含 --timezone 选项并指定时区的规范名称(例如,America/New_York)。有关更多信息,请参阅 https://www.joda.org/joda-time/timezones.html,其中提供了有关致电put-scheduled-action时支持的 IANA 时区的信息。

以下是创建计划操作以在特定日期和时间扩展容量时使用 --timezone 选项的示例。

在为 --schedule 指定的日期和时间(当地时间 2021 年 1 月 31 日下午 5:00),如果为 MinCapacity 指定的值高于当前容量,则 Application Auto Scaling 将横向扩展到 MinCapacity。如果为 MaxCapacity 指定的值低于当前容量,则 Application Auto Scaling 将横向缩减到 MaxCapacity

Linux、macOS 或 Unix

aws application-autoscaling put-scheduled-action --service-namespace comprehend \ --scalable-dimension comprehend:document-classifier-endpoint:DesiredInferenceUnits \ --resource-id arn:aws:comprehend:us-west-2:123456789012:document-classifier-endpoint/EXAMPLE \ --scheduled-action-name my-one-time-action \ --schedule "at(2021-01-31T17:00:00)" --timezone "America/New_York" \ --scalable-target-action MinCapacity=1,MaxCapacity=3

Windows

aws application-autoscaling put-scheduled-action --service-namespace comprehend --scalable-dimension comprehend:document-classifier-endpoint:DesiredInferenceUnits --resource-id arn:aws:comprehend:us-west-2:123456789012:document-classifier-endpoint/EXAMPLE --scheduled-action-name my-one-time-action --schedule "at(2021-01-31T17:00:00)" --timezone "America/New_York" --scalable-target-action MinCapacity=1,MaxCapacity=3

创建指定时区的重复计划操作

以下是创建重复计划操作以扩展容量时使用 --timezone 选项的示例。有关更多信息,请参阅 使用 cron 表达式安排重复发生的扩缩操作

根据指定的计划(当地时间每个星期一到星期五晚上 6:00),如果为 MinCapacity 指定的值高于当前容量,则 Application Auto Scaling 将横向扩展到 MinCapacity。如果为 MaxCapacity 指定的值低于当前容量,则 Application Auto Scaling 将横向缩减到 MaxCapacity

Linux、macOS 或 Unix

aws application-autoscaling put-scheduled-action --service-namespace lambda \ --scalable-dimension lambda:function:ProvisionedConcurrency \ --resource-id function:my-function:BLUE \ --scheduled-action-name my-recurring-action \ --schedule "cron(0 18 ? * MON-FRI *)" --timezone "Etc/GMT+9" \ --scalable-target-action MinCapacity=10,MaxCapacity=50

Windows

aws application-autoscaling put-scheduled-action --service-namespace lambda --scalable-dimension lambda:function:ProvisionedConcurrency --resource-id function:my-function:BLUE --scheduled-action-name my-recurring-action --schedule "cron(0 18 ? * MON-FRI *)" --timezone "Etc/GMT+9" --scalable-target-action MinCapacity=10,MaxCapacity=50