本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 Application Auto Scaling 创建计划操作 Amazon CLI
以下示例说明如何使用 Amazon CLI put-scheduled-action命令创建计划操作。当您指定新容量时,可指定最小容量和/或最大容量。
这些示例对与 Application Auto Scaling 集成的一些服务使用可扩展目标。要使用不同的可扩展目标,请在 --service-namespace 中指定其命名空间,在 --scalable-dimension 中指定其可扩展维度,并在 --resource-id 中指定其资源 ID。
使用时 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-namespacecustom-resource\ --scalable-dimensioncustom-resource:ResourceType:Property\ --resource-idfile://~/custom-resource-id.txt\ --scheduled-action-namescale-out\ --schedule "at(2021-03-31T22:00:00)" \ --scalable-target-action MinCapacity=3
Windows
aws application-autoscaling put-scheduled-action --service-namespacecustom-resource^ --scalable-dimensioncustom-resource:ResourceType:Property^ --resource-idfile://~/custom-resource-id.txt^ --scheduled-action-namescale-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-namespacecustom-resource\ --scalable-dimensioncustom-resource:ResourceType:Property\ --resource-idfile://~/custom-resource-id.txt\ --scheduled-action-namescale-in\ --schedule "at(2021-03-31T22:30:00)" \ --scalable-target-action MinCapacity=0,MaxCapacity=0
Windows
aws application-autoscaling put-scheduled-action --service-namespacecustom-resource^ --scalable-dimensioncustom-resource:ResourceType:Property^ --resource-idfile://~/custom-resource-id.txt^ --scheduled-action-namescale-in^ --schedule "at(2021-03-31T22:30:00)" ^ --scalable-target-action MinCapacity=0,MaxCapacity=0
创建按重复间隔运行的计划操作
要按重复间隔计划扩缩,请使用 --schedule
"rate( 选项。该值必须为正整数。单位可以是 value unit)"minute、minutes、hour、hours、day 或 days。有关更多信息,请参阅 Amazon EventBridge 用户指南中的费率表达式。
以下是使用 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-namespaceecs\ --scalable-dimensionecs:service:DesiredCount\ --resource-idservice/my-cluster/my-service\ --scheduled-action-namemy-recurring-action\ --schedule "rate(5 hours)" \ --start-time2021-01-30T12:00:00\ --end-time2021-01-31T22:00:00\ --scalable-target-action MinCapacity=3,MaxCapacity=10
Windows
aws application-autoscaling put-scheduled-action --service-namespaceecs^ --scalable-dimensionecs:service:DesiredCount^ --resource-idservice/my-cluster/my-service^ --scheduled-action-namemy-recurring-action^ --schedule "rate(5 hours)" ^ --start-time2021-01-30T12:00:00^ --end-time2021-01-31T22:00:00^ --scalable-target-action MinCapacity=3,MaxCapacity=10
创建按重复计划运行的计划操作
要按重复计划来计划扩缩,请使用 --schedule
"cron( 选项。有关更多信息,请参阅 使用 Application Auto Scaling 安排重复性扩展操作。。fields)"
以下是使用 cron 表达式的计划操作的示例。
根据指定的计划(UTC 时间每天上午 9:00),如果为 MinCapacity 指定的值高于当前容量,则 Application Auto Scaling 将横向扩展到 MinCapacity。如果为 MaxCapacity 指定的值低于当前容量,则 Application Auto Scaling 将横向缩减到 MaxCapacity。
Linux、macOS 或 Unix
aws application-autoscaling put-scheduled-action --service-namespaceappstream\ --scalable-dimensionappstream:fleet:DesiredCapacity\ --resource-idfleet/sample-fleet\ --scheduled-action-namemy-recurring-action\ --schedule "cron(0 9 * * ? *)" \ --scalable-target-action MinCapacity=10,MaxCapacity=50
Windows
aws application-autoscaling put-scheduled-action --service-namespaceappstream^ --scalable-dimensionappstream:fleet:DesiredCapacity^ --resource-idfleet/sample-fleet^ --scheduled-action-namemy-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
以下是创建计划操作以在特定日期和时间扩展容量时使用 --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-namespacecomprehend\ --scalable-dimensioncomprehend:document-classifier-endpoint:DesiredInferenceUnits\ --resource-idarn:aws:comprehend:us-west-2:123456789012:document-classifier-endpoint/EXAMPLE\ --scheduled-action-namemy-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-namespacecomprehend^ --scalable-dimensioncomprehend:document-classifier-endpoint:DesiredInferenceUnits^ --resource-idarn:aws:comprehend:us-west-2:123456789012:document-classifier-endpoint/EXAMPLE^ --scheduled-action-namemy-one-time-action^ --schedule "at(2021-01-31T17:00:00)" --timezone "America/New_York" ^ --scalable-target-action MinCapacity=1,MaxCapacity=3
创建指定时区的重复计划操作
以下是创建重复计划操作以扩展容量时使用 --timezone 选项的示例。有关更多信息,请参阅 使用 Application Auto Scaling 安排重复性扩展操作。。
根据指定的计划(当地时间每个星期一到星期五晚上 6:00),如果为 MinCapacity 指定的值高于当前容量,则 Application Auto Scaling 将横向扩展到 MinCapacity。如果为 MaxCapacity 指定的值低于当前容量,则 Application Auto Scaling 将横向缩减到 MaxCapacity。
Linux、macOS 或 Unix
aws application-autoscaling put-scheduled-action --service-namespacelambda\ --scalable-dimensionlambda:function:ProvisionedConcurrency\ --resource-idfunction:my-function:BLUE\ --scheduled-action-namemy-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-namespacelambda^ --scalable-dimensionlambda:function:ProvisionedConcurrency^ --resource-idfunction:my-function:BLUE^ --scheduled-action-namemy-recurring-action^ --schedule "cron(0 18 ? * MON-FRI *)" --timezone "Etc/GMT+9" ^ --scalable-target-action MinCapacity=10,MaxCapacity=50