使用工具的应用程序 Auto Scaling 示例 PowerShell - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

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

使用工具的应用程序 Auto Scaling 示例 PowerShell

以下代码示例向您展示了如何使用与 Application Auto Scaling AWS Tools for PowerShell 配合使用来执行操作和实现常见场景。

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

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

主题

操作

以下代码示例演示如何使用 Add-AASScalableTarget

用于 PowerShell

示例 1:此 cmdlet 注册或更新可扩展目标。可扩展目标是 Application Auto Scaling 可以横向扩展和向内扩展的资源。

Add-AASScalableTarget -ServiceNamespace AppStream -ResourceId fleet/MyFleet -ScalableDimension appstream:fleet:DesiredCapacity -MinCapacity 2 -MaxCapacity 10

以下代码示例演示如何使用 Get-AASScalableTarget

用于 PowerShell

示例 1:此示例将提供有关指定命名空间中应用程序自动缩放可扩展目标的信息。

Get-AASScalableTarget -ServiceNamespace "AppStream"

输出:

CreationTime : 11/7/2019 2:30:03 AM MaxCapacity : 5 MinCapacity : 1 ResourceId : fleet/Test RoleARN : arn:aws:iam::012345678912:role/aws-service-role/appstream.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_AppStreamFleet ScalableDimension : appstream:fleet:DesiredCapacity ServiceNamespace : appstream SuspendedState : Amazon.ApplicationAutoScaling.Model.SuspendedState

以下代码示例演示如何使用 Get-AASScalingActivity

用于 PowerShell

示例 1:提供有关前六周指定命名空间中扩展活动的描述性信息。

Get-AASScalingActivity -ServiceNamespace AppStream

输出:

ActivityId : 2827409f-b639-4cdb-a957-8055d5d07434 Cause : monitor alarm Appstream2-MyFleet-default-scale-in-Alarm in state ALARM triggered policy default-scale-in Description : Setting desired capacity to 2. Details : EndTime : 12/14/2019 11:32:49 AM ResourceId : fleet/MyFleet ScalableDimension : appstream:fleet:DesiredCapacity ServiceNamespace : appstream StartTime : 12/14/2019 11:32:14 AM StatusCode : Successful StatusMessage : Successfully set desired capacity to 2. Change successfully fulfilled by appstream.

以下代码示例演示如何使用 Get-AASScalingPolicy

用于 PowerShell

示例 1:此 cmdlet 描述了指定服务命名空间的 Application Auto Scaling 扩展策略。

Get-AASScalingPolicy -ServiceNamespace AppStream

输出:

Alarms : {Appstream2-LabFleet-default-scale-out-Alarm} CreationTime : 9/3/2019 2:48:15 AM PolicyARN : arn:aws:autoscaling:us-west-2:012345678912:scalingPolicy:5659b069-b5cd-4af1-9f7f-3e956d36233e:resource/appstream/fleet/LabFleet: policyName/default-scale-out PolicyName : default-scale-out PolicyType : StepScaling ResourceId : fleet/LabFleet ScalableDimension : appstream:fleet:DesiredCapacity ServiceNamespace : appstream StepScalingPolicyConfiguration : Amazon.ApplicationAutoScaling.Model.StepScalingPolicyConfiguration TargetTrackingScalingPolicyConfiguration : Alarms : {Appstream2-LabFleet-default-scale-in-Alarm} CreationTime : 9/3/2019 2:48:15 AM PolicyARN : arn:aws:autoscaling:us-west-2:012345678912:scalingPolicy:5659b069-b5cd-4af1-9f7f-3e956d36233e:resource/appstream/fleet/LabFleet: policyName/default-scale-in PolicyName : default-scale-in PolicyType : StepScaling ResourceId : fleet/LabFleet ScalableDimension : appstream:fleet:DesiredCapacity ServiceNamespace : appstream StepScalingPolicyConfiguration : Amazon.ApplicationAutoScaling.Model.StepScalingPolicyConfiguration TargetTrackingScalingPolicyConfiguration :

以下代码示例演示如何使用 Get-AASScheduledAction

用于 PowerShell

示例 1:此 cmdlet 列出了为您的 Auto Scaling 组安排的尚未运行或尚未达到结束时间的操作。

Get-AASScheduledAction -ServiceNamespace AppStream

输出:

CreationTime : 12/22/2019 9:25:52 AM EndTime : 1/1/0001 12:00:00 AM ResourceId : fleet/MyFleet ScalableDimension : appstream:fleet:DesiredCapacity ScalableTargetAction : Amazon.ApplicationAutoScaling.Model.ScalableTargetAction Schedule : cron(0 0 8 ? * MON-FRI *) ScheduledActionARN : arn:aws:autoscaling:us-west-2:012345678912:scheduledAction:4897ca24-3caa-4bf1-8484-851a089b243c:resource/appstream/fleet/MyFleet:scheduledActionName /WeekDaysFleetScaling ScheduledActionName : WeekDaysFleetScaling ServiceNamespace : appstream StartTime : 1/1/0001 12:00:00 AM

以下代码示例演示如何使用 Remove-AASScalableTarget

用于 PowerShell

示例 1:此 cmdlet 注销 Application Auto Scaling 可扩展目标。取消注册可扩展目标会删除与其关联的扩展策略。

Remove-AASScalableTarget -ResourceId fleet/MyFleet -ScalableDimension appstream:fleet:DesiredCapacity -ServiceNamespace AppStream

输出:

Confirm Are you sure you want to perform this action? Performing the operation "Remove-AASScalableTarget (DeregisterScalableTarget)" on target "fleet/MyFleet". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y

以下代码示例演示如何使用 Remove-AASScalingPolicy

用于 PowerShell

示例 1:此 cmdlet 删除了 Application Auto Scaling 可扩展目标的指定扩展策略。

Remove-AASScalingPolicy -ServiceNamespace AppStream -PolicyName "default-scale-out" -ResourceId fleet/Test -ScalableDimension appstream:fleet:DesiredCapacity
  • 有关API详细信息,请参阅 AWS Tools for PowerShell Cmdlet 参考DeleteScalingPolicy中的。

以下代码示例演示如何使用 Remove-AASScheduledAction

用于 PowerShell

示例 1:此 cmdlet 删除了 Application Auto Scaling 可扩展目标的指定计划操作。

Remove-AASScheduledAction -ServiceNamespace AppStream -ScheduledActionName WeekDaysFleetScaling -ResourceId fleet/MyFleet -ScalableDimension appstream:fleet:DesiredCapacity

输出:

Confirm Are you sure you want to perform this action? Performing the operation "Remove-AASScheduledAction (DeleteScheduledAction)" on target "WeekDaysFleetScaling". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y

以下代码示例演示如何使用 Set-AASScalingPolicy

用于 PowerShell

示例 1:此 cmdlet 为 Application Auto Scaling 可扩展目标创建或更新策略。每个可扩展目标都由服务命名空间、资源 ID 和可扩展维度标识。

Set-AASScalingPolicy -ServiceNamespace AppStream -PolicyName ASFleetScaleInPolicy -PolicyType StepScaling -ResourceId fleet/MyFleet -ScalableDimension appstream:fleet:DesiredCapacity -StepScalingPolicyConfiguration_AdjustmentType ChangeInCapacity -StepScalingPolicyConfiguration_Cooldown 360 -StepScalingPolicyConfiguration_MetricAggregationType Average -StepScalingPolicyConfiguration_StepAdjustments @{ScalingAdjustment = -1; MetricIntervalUpperBound = 0}

输出:

Alarms PolicyARN ------ --------- {} arn:aws:autoscaling:us-west-2:012345678912:scalingPolicy:4897ca24-3caa-4bf1-8484-851a089b243c:resource/appstream/fleet/MyFleet:policyName/ASFleetScaleInPolicy
  • 有关API详细信息,请参阅 AWS Tools for PowerShell Cmdlet 参考PutScalingPolicy中的。

以下代码示例演示如何使用 Set-AASScheduledAction

用于 PowerShell

示例 1:此 cmdlet 为 Application Auto Scaling 可扩展目标创建或更新计划操作。每个可扩展目标都由服务命名空间、资源 ID 和可扩展维度标识。

Set-AASScheduledAction -ServiceNamespace AppStream -ResourceId fleet/MyFleet -Schedule "cron(0 0 8 ? * MON-FRI *)" -ScalableDimension appstream:fleet:DesiredCapacity -ScheduledActionName WeekDaysFleetScaling -ScalableTargetAction_MinCapacity 5 -ScalableTargetAction_MaxCapacity 10
  • 有关API详细信息,请参阅 AWS Tools for PowerShell Cmdlet 参考PutScheduledAction中的。