

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

# 使用 的 Application Auto Scaling 範例 AWS CLI
<a name="cli_application-auto-scaling_code_examples"></a>

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

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

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

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

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

### `delete-scaling-policy`
<a name="application-auto-scaling_DeleteScalingPolicy_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-scaling-policy`。

**AWS CLI**  
**刪除擴展政策**  
此範例會刪除在預設叢集中執行之 Amazon ECS 服務 Web 應用程式的擴展政策。  
命令：  

```
aws application-autoscaling delete-scaling-policy --policy-name web-app-cpu-lt-25 --scalable-dimension ecs:service:DesiredCount --resource-id service/default/web-app --service-namespace ecs
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteScalingPolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/application-autoscaling/delete-scaling-policy.html)。

### `delete-scheduled-action`
<a name="application-auto-scaling_DeleteScheduledAction_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-scheduled-action`。

**AWS CLI**  
**刪除排程動作**  
下列`delete-scheduled-action`範例會從指定的 Amazon AppStream 2.0 機群刪除指定的排程動作：  

```
aws application-autoscaling delete-scheduled-action \
    --service-namespace appstream \
    --scalable-dimension appstream:fleet:DesiredCapacity \
    --resource-id fleet/sample-fleet \
    --scheduled-action-name my-recurring-action
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《Application Auto Scaling 使用者指南》**中的[排程擴展](https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-scheduled-scaling.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteScheduledAction](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/application-autoscaling/delete-scheduled-action.html)。

### `deregister-scalable-target`
<a name="application-auto-scaling_DeregisterScalableTarget_cli_topic"></a>

以下程式碼範例顯示如何使用 `deregister-scalable-target`。

**AWS CLI**  
**取消註冊可擴展的目標**  
此範例取消註冊在預設叢集中執行稱為 Web 應用程式之 Amazon ECS 服務的可擴展目標。  
命令：  

```
aws application-autoscaling deregister-scalable-target --service-namespace ecs --scalable-dimension ecs:service:DesiredCount --resource-id service/default/web-app
```
此範例取消註冊自訂資源的可擴展目標。custom-resource-id.txt 檔案包含可識別資源 ID 的字串，而對於自訂資源而言，該字串是經由 Amazon API Gateway 端點前往自訂資源的路徑。  
命令：  

```
aws application-autoscaling deregister-scalable-target --service-namespace custom-resource --scalable-dimension custom-resource:ResourceType:Property --resource-id file://~/custom-resource-id.txt
```
custom-resource-id.txt 檔案的內容：  

```
https://example.execute-api.us-west-2.amazonaws.com/prod/scalableTargetDimensions/1-23456789
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeregisterScalableTarget](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/application-autoscaling/deregister-scalable-target.html)。

### `describe-scalable-targets`
<a name="application-auto-scaling_DescribeScalableTargets_cli_topic"></a>

以下程式碼範例顯示如何使用 `describe-scalable-targets`。

**AWS CLI**  
**描述可擴展的目標**  
下列 `describe-scalable-targets` 範例描述 `ecs` 服務命名空間的可擴展目標。  

```
aws application-autoscaling describe-scalable-targets \
    --service-namespace ecs
```
輸出：  

```
{
    "ScalableTargets": [
        {
            "ServiceNamespace": "ecs",
            "ScalableDimension": "ecs:service:DesiredCount",
            "ResourceId": "service/default/web-app",
            "MinCapacity": 1,
            "MaxCapacity": 10,
            "RoleARN": "arn:aws:iam::123456789012:role/aws-service-role/ecs.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_ECSService",
            "CreationTime": 1462558906.199,
            "SuspendedState": {
                "DynamicScalingOutSuspended": false,
                "ScheduledScalingSuspended": false,
                "DynamicScalingInSuspended": false
            },
            "ScalableTargetARN": "arn:aws:application-autoscaling:us-west-2:123456789012:scalable-target/1234abcd56ab78cd901ef1234567890ab123"
        }
    ]
}
```
如需詳細資訊，請參閱《*Application Auto Scaling 使用者指南*》中的 [AWS 服務可以與 Application Auto Scaling 搭配運作](https://docs.aws.amazon.com/autoscaling/application/userguide/integrated-services-list.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribeScalableTargets](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/application-autoscaling/describe-scalable-targets.html)。

### `describe-scaling-activities`
<a name="application-auto-scaling_DescribeScalingActivities_cli_topic"></a>

以下程式碼範例顯示如何使用 `describe-scaling-activities`。

**AWS CLI**  
**範例 1：描述指定 Amazon ECS 服務的擴展活動**  
下列 `describe-scaling-activities` 範例描述 `default` 叢集中執行之名為 `web-app` 的 Amazon ECS 服務的擴展活動。輸出顯示了由擴展政策啟動的擴展活動。  

```
aws application-autoscaling describe-scaling-activities \
    --service-namespace ecs \
    --resource-id service/default/web-app
```
輸出：  

```
{
    "ScalingActivities": [
        {
            "ScalableDimension": "ecs:service:DesiredCount",
            "Description": "Setting desired count to 1.",
            "ResourceId": "service/default/web-app",
            "ActivityId": "e6c5f7d1-dbbb-4a3f-89b2-51f33e766399",
            "StartTime": 1462575838.171,
            "ServiceNamespace": "ecs",
            "EndTime": 1462575872.111,
            "Cause": "monitor alarm web-app-cpu-lt-25 in state ALARM triggered policy web-app-cpu-lt-25",
            "StatusMessage": "Successfully set desired count to 1. Change successfully fulfilled by ecs.",
            "StatusCode": "Successful"
        }
    ]
}
```
如需詳細資訊，請參閱《*Application Auto Scaling 使用者指南*》中的[適用於 Application Auto Scaling 的擴展活動](https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-scaling-activities.html)。  
**範例 2：描述指定之 DynamoDB 資料表的擴展活動**  
下列 `describe-scaling-activities` 範例描述名為 `TestTable` 之 DynamoDB 資料表的擴展活動。輸出顯示了由兩個不同的排程動作啟動的擴展活動。  

```
aws application-autoscaling describe-scaling-activities \
    --service-namespace dynamodb \
    --resource-id table/TestTable
```
輸出：  

```
{
    "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"
        }
    ]
}
```
如需詳細資訊，請參閱《*Application Auto Scaling 使用者指南*》中的[適用於 Application Auto Scaling 的擴展活動](https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-scaling-activities.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribeScalingActivities](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/application-autoscaling/describe-scaling-activities.html)。

### `describe-scaling-policies`
<a name="application-auto-scaling_DescribeScalingPolicies_cli_topic"></a>

以下程式碼範例顯示如何使用 `describe-scaling-policies`。

**AWS CLI**  
**描述擴展政策**  
此範例命令描述了 ecs 服務命名空間的擴展政策。  
命令：  

```
aws application-autoscaling describe-scaling-policies --service-namespace ecs
```
輸出：  

```
{
    "ScalingPolicies": [
        {
            "PolicyName": "web-app-cpu-gt-75",
            "ScalableDimension": "ecs:service:DesiredCount",
            "ResourceId": "service/default/web-app",
            "CreationTime": 1462561899.23,
            "StepScalingPolicyConfiguration": {
                "Cooldown": 60,
                "StepAdjustments": [
                    {
                        "ScalingAdjustment": 200,
                        "MetricIntervalLowerBound": 0.0
                    }
                ],
                "AdjustmentType": "PercentChangeInCapacity"
            },
            "PolicyARN": "arn:aws:autoscaling:us-west-2:012345678910:scalingPolicy:6d8972f3-efc8-437c-92d1-6270f29a66e7:resource/ecs/service/default/web-app:policyName/web-app-cpu-gt-75",
            "PolicyType": "StepScaling",
            "Alarms": [
                {
                    "AlarmName": "web-app-cpu-gt-75",
                    "AlarmARN": "arn:aws:cloudwatch:us-west-2:012345678910:alarm:web-app-cpu-gt-75"
                }
            ],
            "ServiceNamespace": "ecs"
        },
        {
            "PolicyName": "web-app-cpu-lt-25",
            "ScalableDimension": "ecs:service:DesiredCount",
            "ResourceId": "service/default/web-app",
            "CreationTime": 1462562575.099,
            "StepScalingPolicyConfiguration": {
                "Cooldown": 1,
                "StepAdjustments": [
                    {
                        "ScalingAdjustment": -50,
                        "MetricIntervalUpperBound": 0.0
                    }
                ],
                "AdjustmentType": "PercentChangeInCapacity"
            },
            "PolicyARN": "arn:aws:autoscaling:us-west-2:012345678910:scalingPolicy:6d8972f3-efc8-437c-92d1-6270f29a66e7:resource/ecs/service/default/web-app:policyName/web-app-cpu-lt-25",
            "PolicyType": "StepScaling",
            "Alarms": [
                {
                    "AlarmName": "web-app-cpu-lt-25",
                    "AlarmARN": "arn:aws:cloudwatch:us-west-2:012345678910:alarm:web-app-cpu-lt-25"
                }
            ],
            "ServiceNamespace": "ecs"
        }
    ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribeScalingPolicies](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/application-autoscaling/describe-scaling-policies.html)。

### `describe-scheduled-actions`
<a name="application-auto-scaling_DescribeScheduledActions_cli_topic"></a>

以下程式碼範例顯示如何使用 `describe-scheduled-actions`。

**AWS CLI**  
**描述排程動作**  
下列 `describe-scheduled-actions` 範例顯示指定服務命名空間之排程動作的詳細資訊：  

```
aws application-autoscaling describe-scheduled-actions \
    --service-namespace dynamodb
```
輸出：  

```
{
    "ScheduledActions": [
        {
            "ScalableDimension": "dynamodb:table:WriteCapacityUnits",
            "Schedule": "at(2019-05-20T18:35:00)",
            "ResourceId": "table/my-table",
            "CreationTime": 1561571888.361,
            "ScheduledActionARN": "arn:aws:autoscaling:us-west-2:123456789012:scheduledAction:2d36aa3b-cdf9-4565-b290-81db519b227d:resource/dynamodb/table/my-table:scheduledActionName/my-first-scheduled-action",
            "ScalableTargetAction": {
                "MinCapacity": 15,
                "MaxCapacity": 20
            },
            "ScheduledActionName": "my-first-scheduled-action",
            "ServiceNamespace": "dynamodb"
        },
        {
            "ScalableDimension": "dynamodb:table:WriteCapacityUnits",
            "Schedule": "at(2019-05-20T18:40:00)",
            "ResourceId": "table/my-table",
            "CreationTime": 1561571946.021,
            "ScheduledActionARN": "arn:aws:autoscaling:us-west-2:123456789012:scheduledAction:2d36aa3b-cdf9-4565-b290-81db519b227d:resource/dynamodb/table/my-table:scheduledActionName/my-second-scheduled-action",
            "ScalableTargetAction": {
                "MinCapacity": 5,
                "MaxCapacity": 10
            },
            "ScheduledActionName": "my-second-scheduled-action",
            "ServiceNamespace": "dynamodb"
        }
    ]
}
```
如需詳細資訊，請參閱《Application Auto Scaling 使用者指南》**中的[排程擴展](https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-scheduled-scaling.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribeScheduledActions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/application-autoscaling/describe-scheduled-actions.html)。

### `list-tags-for-resource`
<a name="application-auto-scaling_ListTagsForResource_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-tags-for-resource`。

**AWS CLI**  
**列出可擴展目標的標籤**  
下列 `list-tags-for-resource` 範例列出連接到其 ARN 所指定可擴展目標的標籤索引鍵名稱和值。  

```
aws application-autoscaling list-tags-for-resource \
    --resource-arn arn:aws:application-autoscaling:us-west-2:123456789012:scalable-target/1234abcd56ab78cd901ef1234567890ab123
```
輸出：  

```
{
    "Tags": {
        "environment": "production"
    }
}
```
如需詳細資訊，請參閱《*Application Auto Scaling 使用者指南*》中的[標記 Application Auto Scaling 的支援](https://docs.aws.amazon.com/autoscaling/application/userguide/resource-tagging-support.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/application-autoscaling/list-tags-for-resource.html)。

### `put-scaling-policy`
<a name="application-auto-scaling_PutScalingPolicy_cli_topic"></a>

以下程式碼範例顯示如何使用 `put-scaling-policy`。

**AWS CLI**  
**範例 1：套用具備預先定義指標規格的目標追蹤擴展政策**  
下列 `put-scaling-policy` 範例會將具有預先定義指標規格的目標追蹤政策擴展政策，套用至預設叢集中名為 web-app 的 Amazon ECS 服務。該政策能使服務的平均 CPU 使用率保持在 75%，橫向擴充和縮減冷卻時間為 60 秒。該輸出包含了系統代您建立的兩個 CloudWatch 警示的 ARN 及名稱。  

```
aws application-autoscaling put-scaling-policy --service-namespace ecs \
--scalable-dimension ecs:service:DesiredCount \
--resource-id service/default/web-app \
--policy-name cpu75-target-tracking-scaling-policy --policy-type TargetTrackingScaling \
--target-tracking-scaling-policy-configuration file://config.json
```
此範例假設您在目前目錄中有 config.json 檔案，其中包含下列內容：  

```
{
     "TargetValue": 75.0,
     "PredefinedMetricSpecification": {
         "PredefinedMetricType": "ECSServiceAverageCPUUtilization"
     },
     "ScaleOutCooldown": 60,
    "ScaleInCooldown": 60
}
```
輸出：  

```
{
    "PolicyARN": "arn:aws:autoscaling:us-west-2:012345678910:scalingPolicy:6d8972f3-efc8-437c-92d1-6270f29a66e7:resource/ecs/service/default/web-app:policyName/cpu75-target-tracking-scaling-policy",
    "Alarms": [
        {
            "AlarmARN": "arn:aws:cloudwatch:us-west-2:012345678910:alarm:TargetTracking-service/default/web-app-AlarmHigh-d4f0770c-b46e-434a-a60f-3b36d653feca",
            "AlarmName": "TargetTracking-service/default/web-app-AlarmHigh-d4f0770c-b46e-434a-a60f-3b36d653feca"
        },
        {
            "AlarmARN": "arn:aws:cloudwatch:us-west-2:012345678910:alarm:TargetTracking-service/default/web-app-AlarmLow-1b437334-d19b-4a63-a812-6c67aaf2910d",
            "AlarmName": "TargetTracking-service/default/web-app-AlarmLow-1b437334-d19b-4a63-a812-6c67aaf2910d"
        }
    ]
}
```
**範例 2：套用具備自訂指標規格的目標追蹤擴展政策**  
下列 `put-scaling-policy` 範例會將具有自訂指標規格的目標追蹤政策擴展政策，套用至預設叢集中名為 web-app 的 Amazon ECS 服務。該政策能使服務的平均使用率保持在 75%，橫向擴充和縮減冷卻時間為 60 秒。該輸出包含了系統代您建立的兩個 CloudWatch 警示的 ARN 及名稱。  

```
aws application-autoscaling put-scaling-policy --service-namespace ecs \
--scalable-dimension ecs:service:DesiredCount \
--resource-id service/default/web-app \
--policy-name cms75-target-tracking-scaling-policy
--policy-type TargetTrackingScaling \
--target-tracking-scaling-policy-configuration file://config.json
```
此範例假設您在目前目錄中有 config.json 檔案，其中包含下列內容：  

```
{
    "TargetValue":75.0,
    "CustomizedMetricSpecification":{
        "MetricName":"MyUtilizationMetric",
        "Namespace":"MyNamespace",
        "Dimensions": [
            {
                "Name":"MyOptionalMetricDimensionName",
                "Value":"MyOptionalMetricDimensionValue"
            }
        ],
        "Statistic":"Average",
        "Unit":"Percent"
    },
    "ScaleOutCooldown": 60,
    "ScaleInCooldown": 60
}
```
輸出：  

```
{
    "PolicyARN": "arn:aws:autoscaling:us-west-2:012345678910:scalingPolicy: 8784a896-b2ba-47a1-b08c-27301cc499a1:resource/ecs/service/default/web-app:policyName/cms75-target-tracking-scaling-policy",
    "Alarms": [
        {
            "AlarmARN": "arn:aws:cloudwatch:us-west-2:012345678910:alarm:TargetTracking-service/default/web-app-AlarmHigh-9bc77b56-0571-4276-ba0f-d4178882e0a0",
            "AlarmName": "TargetTracking-service/default/web-app-AlarmHigh-9bc77b56-0571-4276-ba0f-d4178882e0a0"
        },
        {
            "AlarmARN": "arn:aws:cloudwatch:us-west-2:012345678910:alarm:TargetTracking-service/default/web-app-AlarmLow-9b6ad934-6d37-438e-9e05-02836ddcbdc4",
            "AlarmName": "TargetTracking-service/default/web-app-AlarmLow-9b6ad934-6d37-438e-9e05-02836ddcbdc4"
        }
    ]
}
```
**範例 3：只針對橫向擴展套用目標追蹤擴展政策**  
下列 `put-scaling-policy` 範例會將目標追蹤擴展政策套用至預設叢集中名為 `web-app` 的 Amazon ECS 服務。當 Application Load Balancer 的 `RequestCountPerTarget` 指標超過閾值時，會利用此政策橫向擴充 ECS 服務。該輸出包含了系統代您建立的 CloudWatch 警示的 ARN 及名稱。  

```
aws application-autoscaling put-scaling-policy \
    --service-namespace ecs \
    --scalable-dimension ecs:service:DesiredCount \
    --resource-id service/default/web-app \
    --policy-name alb-scale-out-target-tracking-scaling-policy \
    --policy-type TargetTrackingScaling \
    --target-tracking-scaling-policy-configuration file://config.json
```
`config.json` 的內容：  

```
{
     "TargetValue": 1000.0,
     "PredefinedMetricSpecification": {
         "PredefinedMetricType": "ALBRequestCountPerTarget",
         "ResourceLabel": "app/EC2Co-EcsEl-1TKLTMITMM0EO/f37c06a68c1748aa/targetgroup/EC2Co-Defau-LDNM7Q3ZH1ZN/6d4ea56ca2d6a18d"
     },
     "ScaleOutCooldown": 60,
    "ScaleInCooldown": 60,
    "DisableScaleIn": true
}
```
輸出：  

```
{
    "PolicyARN": "arn:aws:autoscaling:us-west-2:123456789012:scalingPolicy:6d8972f3-efc8-437c-92d1-6270f29a66e7:resource/ecs/service/default/web-app:policyName/alb-scale-out-target-tracking-scaling-policy",
    "Alarms": [
        {
            "AlarmName": "TargetTracking-service/default/web-app-AlarmHigh-d4f0770c-b46e-434a-a60f-3b36d653feca",
            "AlarmARN": "arn:aws:cloudwatch:us-west-2:123456789012:alarm:TargetTracking-service/default/web-app-AlarmHigh-d4f0770c-b46e-434a-a60f-3b36d653feca"
        }
    ]
}
```
如需詳細資訊，請參閱《*AWS Application Auto Scaling 使用者指南*》中的 [Application Auto Scaling 目標追蹤擴展政策](https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-target-tracking.html)。  
+  如需 API 詳細資訊，請參閱《*AWS CLI 命令參考*》中的 [PutScalingPolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/application-autoscaling/put-scaling-policy.html)。

### `put-scheduled-action`
<a name="application-auto-scaling_PutScheduledAction_cli_topic"></a>

以下程式碼範例顯示如何使用 `put-scheduled-action`。

**AWS CLI**  
**將排程動作新增至 DynamoDB 資料表**  
此範例將排程動作新增至名為 TestTable 的 DynamoDB 資料表，以根據週期性排程橫向擴充。在指定的排程期間 (每天 UTC 時間中午 12:15 時)，若目前容量低於為 MinCapacity 指定的值，則 Application Auto Scaling 會橫向擴充至指定的值。  
命令：  

```
aws application-autoscaling put-scheduled-action --service-namespace dynamodb --scheduled-action-name my-recurring-action --schedule "cron(15 12 * * ? *)" --resource-id table/TestTable --scalable-dimension dynamodb:table:WriteCapacityUnits --scalable-target-action MinCapacity=6
```
如需詳細資訊，請參閱《*Application Auto Scaling 使用者指南*》中的排程擴展。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [PutScheduledAction](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/application-autoscaling/put-scheduled-action.html)。

### `register-scalable-target`
<a name="application-auto-scaling_RegisterScalableTarget_cli_topic"></a>

以下程式碼範例顯示如何使用 `register-scalable-target`。

**AWS CLI**  
**範例 1：將 ECS 服務註冊為可擴展的目標**  
下列 `register-scalable-target` 範例向 Application Auto Scaling 註冊 Amazon ECS 服務。該範例也會將具有金鑰名稱 `environment` 和值 `production` 的標籤新增至可擴展的目標。  

```
aws application-autoscaling register-scalable-target \
    --service-namespace ecs \
    --scalable-dimension ecs:service:DesiredCount \
    --resource-id service/default/web-app \
    --min-capacity 1 --max-capacity 10 \
    --tags environment=production
```
輸出：  

```
{
    "ScalableTargetARN": "arn:aws:application-autoscaling:us-west-2:123456789012:scalable-target/1234abcd56ab78cd901ef1234567890ab123"
}
```
如需其他服務 AWS 和自訂資源的範例，請參閱《Application [AWS Auto Scaling 使用者指南》中的可與 Application Auto Scaling 搭配使用之服務](https://docs.aws.amazon.com/autoscaling/application/userguide/integrated-services-list.html)中的主題。 * Auto Scaling *  
**範例 2：暫停可擴展目標的擴展活動**  
下列 `register-scalable-target` 範例暫停現有可擴展目標的擴展活動。  

```
aws application-autoscaling register-scalable-target \
    --service-namespace dynamodb \
    --scalable-dimension dynamodb:table:ReadCapacityUnits \
    --resource-id table/my-table \
    --suspended-state DynamicScalingInSuspended=true,DynamicScalingOutSuspended=true,ScheduledScalingSuspended=true
```
輸出：  

```
{
    "ScalableTargetARN": "arn:aws:application-autoscaling:us-west-2:123456789012:scalable-target/1234abcd56ab78cd901ef1234567890ab123"
}
```
如需詳細資訊，請參閱《*Application Auto Scaling User Guide 使用者指南*》中的 [Application Auto Scaling 暫停和繼續擴展](https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-suspend-resume-scaling.html)。  
**範例 3：恢復可擴展目標的擴展活動**  
以下 `register-scalable-target` 範例命令會恢復現有可擴展目標的擴展活動。  

```
aws application-autoscaling register-scalable-target \
    --service-namespace dynamodb \
    --scalable-dimension dynamodb:table:ReadCapacityUnits \
    --resource-id table/my-table \
    --suspended-state DynamicScalingInSuspended=false,DynamicScalingOutSuspended=false,ScheduledScalingSuspended=false
```
輸出：  

```
{
    "ScalableTargetARN": "arn:aws:application-autoscaling:us-west-2:123456789012:scalable-target/1234abcd56ab78cd901ef1234567890ab123"
}
```
如需詳細資訊，請參閱《*Application Auto Scaling User Guide 使用者指南*》中的 [Application Auto Scaling 暫停和繼續擴展](https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-suspend-resume-scaling.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [RegisterScalableTarget](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/application-autoscaling/register-scalable-target.html)。

### `tag-resource`
<a name="application-auto-scaling_TagResource_cli_topic"></a>

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

**AWS CLI**  
**將標籤新增至可擴展的目標**  
下列 `tag-resource` 範例將具有索引鍵名稱 `environment` 和值的標籤，新增至其 ARN 指定的 `production` 可擴展目標。  

```
aws application-autoscaling tag-resource \
    --resource-arn arn:aws:application-autoscaling:us-west-2:123456789012:scalable-target/1234abcd56ab78cd901ef1234567890ab123 \
    --tags environment=production
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《*Application Auto Scaling 使用者指南*》中的[標記 Application Auto Scaling 的支援](https://docs.aws.amazon.com/autoscaling/application/userguide/resource-tagging-support.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/application-autoscaling/tag-resource.html)。

### `untag-resource`
<a name="application-auto-scaling_UntagResource_cli_topic"></a>

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

**AWS CLI**  
**從可擴展的目標移除標籤**  
下列 `untag-resource` 範例從其 ARN 指定的可擴展目標移除具有索引鍵名稱 `environment` 的標籤對。  

```
aws application-autoscaling untag-resource \
    --resource-arn arn:aws:application-autoscaling:us-west-2:123456789012:scalable-target/1234abcd56ab78cd901ef1234567890ab123 \
    --tag-keys "environment"
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《*Application Auto Scaling 使用者指南*》中的[標記 Application Auto Scaling 的支援](https://docs.aws.amazon.com/autoscaling/application/userguide/resource-tagging-support.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/application-autoscaling/untag-resource.html)。