使用 Tools for PowerShell 的 Application Auto Scaling 範例 - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 Tools for PowerShell 的 Application Auto Scaling 範例

下列程式碼範例示範如何 AWS Tools for PowerShell 搭配 Application Auto Scaling 使用 來執行動作和實作常見案例。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然 動作會示範如何呼叫個別服務函數,但您可以在其相關案例中查看內容中的動作。

每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

下列程式碼範例示範如何使用 Add-AASScalableTarget

for PowerShell 工具

範例 1:此 cmdlet 會註冊或更新可擴展目標。可擴展目標是 Application Auto Scaling 可以橫向擴展和橫向擴展的資源。

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

下列程式碼範例示範如何使用 Get-AASScalableTarget

for PowerShell 工具

範例 1:此範例將提供指定命名空間中 Application Autoscaling 可擴展目標的相關資訊。

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

for 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

for 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

for 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

for 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

for 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

for 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
  • 如需 API 詳細資訊,請參閱 AWS Tools for PowerShell Cmdlet 參考中的 DeleteScheduledAction

下列程式碼範例示範如何使用 Set-AASScalingPolicy

for 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

for 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