本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
管理 Application Auto Scaling 的计划扩缩
Amazon CLI 包括其他几个可帮助您管理计划操作的命令。
为简洁起见,本主题中的示例说明与 Application Auto Scaling 集成的一些服务的 CLI 命令。要指定不同的可扩展目标,请在 --service-namespace
中指定其命名空间,在 --scalable-dimension
中指定其可扩展维度,并在 --resource-id
中指定其资源 ID。有关每项服务的更多信息和示例,请参阅 Amazon Web Services 可以与 Application Auto Scaling 一起使用 中的主题。
使用时 Amazon CLI,请记住您的命令在 Amazon Web Services 区域 配置文件中运行。如果您想要在不同的区域中运行命令,可以为配置文件更改默认区域,或者与命令一起使用 --region
参数。
查看指定服务的扩缩活动
要查看指定服务命名空间中所有可扩展目标的扩缩活动,请使用 describe-scaling-activities 命令。
以下示例检索与 dynamodb
服务命名空间关联的扩缩活动。
Linux、macOS 或 Unix
aws application-autoscaling describe-scaling-activities --service-namespace
dynamodb
Windows
aws application-autoscaling describe-scaling-activities --service-namespace
dynamodb
如果命令成功,则将显示类似于以下内容的输出。
{
"ScalingActivities": [
{
"ScalableDimension": "dynamodb:table:WriteCapacityUnits",
"Description": "Setting write capacity units to 10.",
"ResourceId": "table/my-table",
"ActivityId": "4d1308c0-bbcf-4514-a673-b0220ae38547",
"StartTime": 1561574415.086,
"ServiceNamespace": "dynamodb",
"EndTime": 1561574449.51,
"Cause": "maximum capacity was set to 10",
"StatusMessage": "Successfully set write capacity units to 10. Change successfully fulfilled by dynamodb.",
"StatusCode": "Successful"
},
{
"ScalableDimension": "dynamodb:table:WriteCapacityUnits",
"Description": "Setting min capacity to 5 and max capacity to 10",
"ResourceId": "table/my-table",
"ActivityId": "f2b7847b-721d-4e01-8ef0-0c8d3bacc1c7",
"StartTime": 1561574414.644,
"ServiceNamespace": "dynamodb",
"Cause": "scheduled action name my-second-scheduled-action was triggered",
"StatusMessage": "Successfully set min capacity to 5 and max capacity to 10",
"StatusCode": "Successful"
},
{
"ScalableDimension": "dynamodb:table:WriteCapacityUnits",
"Description": "Setting write capacity units to 15.",
"ResourceId": "table/my-table",
"ActivityId": "d8ea4de6-9eaa-499f-b466-2cc5e681ba8b",
"StartTime": 1561574108.904,
"ServiceNamespace": "dynamodb",
"EndTime": 1561574140.255,
"Cause": "minimum capacity was set to 15",
"StatusMessage": "Successfully set write capacity units to 15. Change successfully fulfilled by dynamodb.",
"StatusCode": "Successful"
},
{
"ScalableDimension": "dynamodb:table:WriteCapacityUnits",
"Description": "Setting min capacity to 15 and max capacity to 20",
"ResourceId": "table/my-table",
"ActivityId": "3250fd06-6940-4e8e-bb1f-d494db7554d2",
"StartTime": 1561574108.512,
"ServiceNamespace": "dynamodb",
"Cause": "scheduled action name my-first-scheduled-action was triggered",
"StatusMessage": "Successfully set min capacity to 15 and max capacity to 20",
"StatusCode": "Successful"
}
]
}
要更改此命令以使其仅检索其中一个可扩展目标的扩缩活动,请添加 --resource-id
选项。
描述指定服务的所有计划操作
要描述指定服务命名空间中所有可扩展目标的计划操作,请使用 describe-scheduled-actions 命令。
以下示例检索与 ec2
服务命名空间关联的计划操作。
Linux、macOS 或 Unix
aws application-autoscaling describe-scheduled-actions --service-namespace
ec2
Windows
aws application-autoscaling describe-scheduled-actions --service-namespace
ec2
如果成功,该命令返回类似以下内容的输出。
{
"ScheduledActions": [
{
"ScheduledActionName": "my-one-time-action",
"ScheduledActionARN": "arn:aws:autoscaling:us-west-2:123456789012:scheduledAction:493a6261-fbb9-432d-855d-3c302c14bdb9:resource/ec2/spot-fleet-request/sfr-107dc873-0802-4402-a901-37294EXAMPLE:scheduledActionName/my-one-time-action",
"ServiceNamespace": "ec2",
"Schedule": "at(2021-01-31T17:00:00)",
"Timezone": "America/New_York",
"ResourceId": "spot-fleet-request/sfr-107dc873-0802-4402-a901-37294EXAMPLE",
"ScalableDimension": "ec2:spot-fleet-request:TargetCapacity",
"ScalableTargetAction": {
"MaxCapacity": 1
},
"CreationTime": 1607454792.331
},
{
"ScheduledActionName": "my-recurring-action",
"ScheduledActionARN": "arn:aws:autoscaling:us-west-2:123456789012:scheduledAction:493a6261-fbb9-432d-855d-3c302c14bdb9:resource/ec2/spot-fleet-request/sfr-107dc873-0802-4402-a901-37294EXAMPLE:scheduledActionName/my-recurring-action",
"ServiceNamespace": "ec2",
"Schedule": "rate(5 minutes)",
"ResourceId": "spot-fleet-request/sfr-107dc873-0802-4402-a901-37294EXAMPLE",
"ScalableDimension": "ec2:spot-fleet-request:TargetCapacity",
"StartTime": 1604059200.0,
"EndTime": 1612130400.0,
"ScalableTargetAction": {
"MinCapacity": 3,
"MaxCapacity": 10
},
"CreationTime": 1607454949.719
},
{
"ScheduledActionName": "my-one-time-action",
"ScheduledActionARN": "arn:aws:autoscaling:us-west-2:123456789012:scheduledAction:4bce34c7-bb81-4ecf-b776-5c726efb1567:resource/ec2/spot-fleet-request/sfr-40edeb7b-9ae7-44be-bef2-5c4c8EXAMPLE:scheduledActionName/my-one-time-action",
"ServiceNamespace": "ec2",
"Schedule": "at(2020-12-08T9:36:00)",
"Timezone": "America/New_York",
"ResourceId": "spot-fleet-request/sfr-40edeb7b-9ae7-44be-bef2-5c4c8EXAMPLE",
"ScalableDimension": "ec2:spot-fleet-request:TargetCapacity",
"ScalableTargetAction": {
"MinCapacity": 1,
"MaxCapacity": 3
},
"CreationTime": 1607456031.391
}
]
}
描述可扩展目标的一个或多个计划操作
要检索有关指定可扩展目标的计划操作的信息,请在使用 describe-scheduled-actions 命令描述计划操作时添加 --resource-id
选项。
如果您包含 --scheduled-action-names
选项并将计划操作的名称指定为其值,则该命令仅返回名称匹配的计划操作,如以下示例所示。
Linux、macOS 或 Unix
aws application-autoscaling describe-scheduled-actions --service-namespace
ec2
\ --resource-idspot-fleet-request/sfr-40edeb7b-9ae7-44be-bef2-5c4c8EXAMPLE
\ --scheduled-action-namesmy-one-time-action
Windows
aws application-autoscaling describe-scheduled-actions --service-namespace
ec2
--resource-idspot-fleet-request/sfr-40edeb7b-9ae7-44be-bef2-5c4c8EXAMPLE
--scheduled-action-namesmy-one-time-action
下面是示例输出。
{
"ScheduledActions": [
{
"ScheduledActionName": "my-one-time-action",
"ScheduledActionARN": "arn:aws:autoscaling:us-west-2:123456789012:scheduledAction:4bce34c7-bb81-4ecf-b776-5c726efb1567:resource/ec2/spot-fleet-request/sfr-40edeb7b-9ae7-44be-bef2-5c4c8EXAMPLE:scheduledActionName/my-one-time-action",
"ServiceNamespace": "ec2",
"Schedule": "at(2020-12-08T9:36:00)",
"Timezone": "America/New_York",
"ResourceId": "spot-fleet-request/sfr-40edeb7b-9ae7-44be-bef2-5c4c8EXAMPLE",
"ScalableDimension": "ec2:spot-fleet-request:TargetCapacity",
"ScalableTargetAction": {
"MinCapacity": 1,
"MaxCapacity": 3
},
"CreationTime": 1607456031.391
}
]
}
如果为 --scheduled-action-names
选项提供多个值,则名称匹配的所有计划操作都包含在输出中。
关闭可扩展目标的计划扩缩
您可以暂时关闭计划扩缩而不删除您的计划操作。有关更多信息,请参阅 暂停和恢复 Application Auto Scaling 扩缩。
通过使用 register-scalable-target 命令及 --suspended-state
选项,并指定 true
作为 ScheduledScalingSuspended
属性的值,暂停可扩展目标的计划扩缩,如以下示例所示。
Linux、macOS 或 Unix
aws application-autoscaling register-scalable-target --service-namespace
rds
\ --scalable-dimensionrds:cluster:ReadReplicaCount
--resource-idcluster:my-db-cluster
\ --suspended-state '{"ScheduledScalingSuspended": true}'
Windows
aws application-autoscaling register-scalable-target --service-namespace
rds
--scalable-dimensionrds:cluster:ReadReplicaCount
--resource-idcluster:my-db-cluster
--suspended-state "{\"ScheduledScalingSuspended\": true}"
如果成功,该命令会返回可扩展目标的 ARN。
{
"ScalableTargetARN": "arn:aws:application-autoscaling:region
:account-id
:scalable-target/1234abcd56ab78cd901ef1234567890ab123"
}
要恢复计划扩缩,请再次运行此命令,指定 false
作为 ScheduledScalingSuspended
属性的值。
删除计划的操作
完成计划的操作后,您可以使用 delete-scheduled-action 命令将其删除。
Linux、macOS 或 Unix
aws application-autoscaling delete-scheduled-action --service-namespace
ec2
\ --scalable-dimensionec2:spot-fleet-request:TargetCapacity
\ --resource-idspot-fleet-request/sfr-73fbd2ce-aa30-494c-8788-37294EXAMPLE
\ --scheduled-action-namemy-recurring-action
Windows
aws application-autoscaling delete-scheduled-action --service-namespace
ec2
--scalable-dimensionec2:spot-fleet-request:TargetCapacity
--resource-idspot-fleet-request/sfr-73fbd2ce-aa30-494c-8788-37294EXAMPLE
--scheduled-action-namemy-recurring-action
如果成功,该命令将返回到提示符。