

第 5 版 (V5) AWS Tools for PowerShell 已發行！

如需有關中斷變更和遷移應用程式的資訊，請參閱[遷移主題](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)。

 [https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)

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

# 使用 Tools for PowerShell V5 的 Application Auto Scaling 範例
<a name="powershell_application-auto-scaling_code_examples"></a>

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

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

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

**Topics**
+ [動作](#actions)

## 動作
<a name="actions"></a>

### `Add-AASScalableTarget`
<a name="application-auto-scaling_RegisterScalableTarget_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Add-AASScalableTarget`。

**Tools for PowerShell V5**  
**範例 1：此 Cmdlet 會註冊或更新可擴展的目標。可擴展的目標是 Application Auto Scaling 可橫向擴充和縮減的資源。**  

```
Add-AASScalableTarget -ServiceNamespace AppStream -ResourceId fleet/MyFleet -ScalableDimension appstream:fleet:DesiredCapacity -MinCapacity 2 -MaxCapacity 10
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [RegisterScalableTarget](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-AASScalableTarget`
<a name="application-auto-scaling_DescribeScalableTargets_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Get-AASScalableTarget`。

**Tools for PowerShell V5**  
**範例 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
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeScalableTargets](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-AASScalingActivity`
<a name="application-auto-scaling_DescribeScalingActivities_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Get-AASScalingActivity`。

**Tools for PowerShell V5**  
**範例 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.
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeScalingActivities](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-AASScalingPolicy`
<a name="application-auto-scaling_DescribeScalingPolicies_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Get-AASScalingPolicy`。

**Tools for PowerShell V5**  
**範例 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 :
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeScalingPolicies](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-AASScheduledAction`
<a name="application-auto-scaling_DescribeScheduledActions_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Get-AASScheduledAction`。

**Tools for PowerShell V5**  
**範例 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
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeScheduledActions](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-AASScalableTarget`
<a name="application-auto-scaling_DeregisterScalableTarget_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-AASScalableTarget`。

**Tools for PowerShell V5**  
**範例 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
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeregisterScalableTarget](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-AASScalingPolicy`
<a name="application-auto-scaling_DeleteScalingPolicy_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-AASScalingPolicy`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [DeleteScalingPolicy](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Remove-AASScheduledAction`
<a name="application-auto-scaling_DeleteScheduledAction_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Remove-AASScheduledAction`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [DeleteScheduledAction](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Set-AASScalingPolicy`
<a name="application-auto-scaling_PutScalingPolicy_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Set-AASScalingPolicy`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [PutScalingPolicy](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Set-AASScheduledAction`
<a name="application-auto-scaling_PutScheduledAction_powershell_topic"></a>

以下程式碼範例顯示如何使用 `Set-AASScheduledAction`。

**Tools for PowerShell V5**  
**範例 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 參考 (V5)》**中的 [PutScheduledAction](https://docs.aws.amazon.com/powershell/v5/reference)。