

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

# 排程擴展
<a name="AutoScaling-with-Scheduled-Scaling-Shards"></a>

按照排程進行擴展讓您能夠因應可預測的需求變化，據以擴展您的應用程式。若要使用排程擴展，您可以建立排程動作，指示 ElastiCache for Valkey 和 Redis OSS 在特定時間執行擴展活動。當您建立排程動作時，您可以指定現有的叢集、應進行擴展活動的時間、最小容量和最大容量。您可以建立僅擴展一次或依週期性排程擴展的排程動作。

 您只能為已存在的叢集建立排程動作。您無法在建立叢集的同時建立排程動作。

如需排程動作建立、管理和刪除作業相關術語的詳細資訊，請參閱[排程動作建立、管理和刪除作業常用的命令](https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-scheduled-scaling.html#scheduled-scaling-commonly-used-commands) 

**若要建立週期性排程：**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/elasticache/](https://console.aws.amazon.com/elasticache/)：// 開啟 Amazon ElastiCache 主控台。

1. 在導覽窗格中，選擇 **Valkey** 或 **Redis OSS**。

1. 選擇您要新增政策的叢集。

1. 從 **Actions (動作)** 下拉式選單中選擇 **Manage Auto Scaling policies (管理 Auto Scaling 政策)**。

1. 選擇 **Auto Scaling policies (Auto Scaling 政策)** 索引標籤。

1. 在 **Auto scaling policies (Auto Scaling 政策)** 區段中，會出現 **Add Scaling policy (新增規模調整政策)** 對話方塊。選擇 **Scheduled scaling (排程規模調整)**。

1. 在 **Policy Name (政策名稱)** 輸入政策的名稱。

1. 在 **Scalable Dimension (可擴展的維度)** 選擇 **Shards (碎片)**。

1. 在 **Target Shards (目標碎片)** 選擇值。

1. 在 **Recurrence (重複)** 選擇 **Recurring (週期性)**。

1. 在 **Frequency (頻率)** 選擇各自的值。

1. 在 **Start Date (開始日期)** 和 **Start time (開始時間)** 選擇政策生效的時間。

1. 選擇 **Add Policy (新增政策)**。

**若要建立一次性排程動作：**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/elasticache/](https://console.aws.amazon.com/elasticache/)：// 開啟 Amazon ElastiCache 主控台。

1. 在導覽窗格中，選擇 **Valkey** 或 **Redis OSS**。

1. 選擇您要新增政策的叢集。

1. 從 **Actions (動作)** 下拉式選單中選擇 **Manage Auto Scaling policies (管理 Auto Scaling 政策)**。

1. 選擇 **Auto Scaling policies (Auto Scaling 政策)** 索引標籤。

1. 在 **Auto scaling policies (Auto Scaling 政策)** 區段中，會出現 **Add Scaling policy (新增規模調整政策)** 對話方塊。選擇 **Scheduled scaling (排程規模調整)**。

1. 在 **Policy Name (政策名稱)** 輸入政策的名稱。

1. 在 **Scalable Dimension (可擴展的維度)** 選擇 **Shards (碎片)**。

1. 在 **Target Shards (目標碎片)** 選擇值。

1. 在 **Recurrence (重複)**，選擇 **Once (一次)**。

1. 在 **Start Date (開始日期)** 和 **Start time (開始時間)** 選擇政策生效的時間。

1. 在 **End Date (結束日期)** 選擇政策效用結束的日期。

1. 選擇 **Add Policy (新增政策)**。

**刪除排程動作**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/elasticache/](https://console.aws.amazon.com/elasticache/)：// 開啟 Amazon ElastiCache 主控台。

1. 在導覽窗格中，選擇 **Valkey** 或 **Redis OSS**。

1. 選擇您要新增政策的叢集。

1. 從 **Actions (動作)** 下拉式選單中選擇 **Manage Auto Scaling policies (管理 Auto Scaling 政策)**。

1. 選擇 **Auto Scaling policies (Auto Scaling 政策)** 索引標籤。

1. 在 **Auto Scaling policies (Auto Scaling 政策)** 區段中，選擇 Auto Scaling 政策，然後從 **Actions (動作)** 對話中選擇 **Delete (刪除)**。

**使用 AWS CLI 管理排定的擴展**

使用下列 application-autoscaling API：
+ [put-scheduled-action](https://docs.aws.amazon.com/cli/latest/reference/autoscaling/put-scheduled-action.html) 
+ [describe-scheduled-actions](https://docs.aws.amazon.com/cli/latest/reference/autoscaling/describe-scheduled-actions.html) 
+ [delete-scheduled-action](https://docs.aws.amazon.com/cli/latest/reference/autoscaling/delete-scheduled-action.html) 

## 使用 CloudFormation 建立排程動作
<a name="AutoScaling-with-Cloudformation-Declare-Scheduled-Action"></a>

此程式碼片段示範如何建立目標追蹤政策，並使用 [AWS::ApplicationAutoScaling::ScalableTarget](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-applicationautoscaling-scalabletarget.html) 資源將其套用至 [AWS::ElastiCache::ReplicationGroup](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticache-replicationgroup.html) 資源。其使用 [Fn::Join](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-join.html) 和 [Ref](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html) 內部函數來建構 `ResourceId` 屬性，該屬性具有相同範本中指定的 `AWS::ElastiCache::ReplicationGroup` 資源的邏輯名稱。

```
ScalingTarget:
   Type: 'AWS::ApplicationAutoScaling::ScalableTarget'
   Properties:
     MaxCapacity: 3
     MinCapacity: 1
     ResourceId: !Sub replication-group/${logicalName}
     ScalableDimension: 'elasticache:replication-group:NodeGroups'
     ServiceNamespace: elasticache
     RoleARN: !Sub "arn:aws:iam::${AWS::AccountId}:role/aws-service-role/elasticache.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_ElastiCacheRG"
     ScheduledActions:
       - EndTime: '2020-12-31T12:00:00.000Z'
         ScalableTargetAction:
           MaxCapacity: '5'
           MinCapacity: '2'
         ScheduledActionName: First
         Schedule: 'cron(0 18 * * ? *)'
```