

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

# ElastiCache 和 Application Auto Scaling
<a name="services-that-can-integrate-elasticache"></a>

您可以使用目標追蹤擴展政策和排程擴展，水平擴展 Amazon ElastiCache 複寫群組 (Redis OSS 和 Valkey) 和 Memcached 自行設計的叢集。

若要將 ElastiCache 與 Application Auto Scaling 整合，請使用下列資訊。

## 為 ElastiCache 建立的服務連結角色
<a name="integrate-service-linked-role-elasticache"></a>

使用 Application Auto Scaling 將 ElastiCache 資源註冊為可擴展的目標 AWS 帳戶 時，會在 中自動建立下列服務連結角色。此角色可讓 Application Auto Scaling 在您的帳戶內執行支援的操作。如需詳細資訊，請參閱[Application Auto Scaling 的服務連結角色](application-auto-scaling-service-linked-roles.md)。
+ `AWSServiceRoleForApplicationAutoScaling_ElastiCacheRG`

## 服務連結角色所使用的服務委託人
<a name="integrate-service-principal-elasticache"></a>

上一節中的服務連結角色，只能由依據角色定義的信任關係所授權的服務委託人來擔任。Application Auto Scaling 使用的服務連結角色會將存取權授予下列服務委託人：
+ `elasticache.application-autoscaling.amazonaws.com`

## 使用 Application Auto Scaling 將 ElastiCache 資源註冊為可擴展的目標
<a name="integrate-register-elasticache"></a>

Application Auto Scaling 需要可擴展的目標，才能為 ElastiCache 複寫群組、叢集或節點建立擴展政策或排程動作。可擴展的目標是 Application Auto Scaling 可水平擴展和縮減的資源。可擴展的目標是由資源 ID、可擴展的維度和命名空間的組合來唯一識別。

如果您使用 ElastiCache 主控台設定自動擴展，則 ElastiCache 會自動為您註冊可擴展的目標。

如果您想要使用 CLI 或其中一個 AWS SDKs AWS 設定自動擴展，您可以使用下列選項：
+ AWS CLI: 

  為 ElastiCache 複寫群組呼叫 [register-scalable-target](https://docs.aws.amazon.com/cli/latest/reference/application-autoscaling/register-scalable-target.html) 命令。以下範例替名為 `mycluster1` 的複寫群組註冊所需的節點群組數量，容量下限為 1，容量上限為 5。

  ```
  aws application-autoscaling register-scalable-target \
     --service-namespace elasticache \
     --scalable-dimension elasticache:replication-group:NodeGroups \
     --resource-id replication-group/mycluster1 \
     --min-capacity 1 \
     --max-capacity 5
  ```

  如果成功，此命令會傳回可擴展目標的 ARN。

  ```
  {
      "ScalableTargetARN": "arn:aws:application-autoscaling:region:account-id:scalable-target/1234abcd56ab78cd901ef1234567890ab123"
  }
  ```

  下列範例會為名為 的複寫群組，註冊每個節點群組所需的複本數量`mycluster2`，最小容量為 1，最大容量為 5。

  ```
  aws application-autoscaling register-scalable-target \
     --service-namespace elasticache \
     --scalable-dimension elasticache:replication-group:Replicas \
     --resource-id replication-group/mycluster2 \
     --min-capacity 1 \
     --max-capacity 5
  ```

  如果成功，此命令會傳回可擴展目標的 ARN。

  ```
  {
      "ScalableTargetARN": "arn:aws:application-autoscaling:region:account-id:scalable-target/234abcd56ab78cd901ef1234567890ab1234"
  }
  ```

  下列範例會為名為 的叢集註冊所需的節點數量`mynode1`，容量下限為 20，容量上限為 50。

  ```
  aws application-autoscaling register-scalable-target \
     --service-namespace elasticache \
     --scalable-dimension elasticache:cache-cluster:Nodes \
     --resource-id cache-cluster/mynode1 \
     --min-capacity 20 \
     --max-capacity 50
  ```

  如果成功，此命令會傳回可擴展目標的 ARN。

  ```
  {
      "ScalableTargetARN": "arn:aws:application-autoscaling:region:account-id:scalable-target/01234abcd56ab78cd901ef1234567890ab12"
  }
  ```
+ AWS 開發套件：

  呼叫 [RegisterScalableTarget](https://docs.aws.amazon.com/autoscaling/application/APIReference/API_RegisterScalableTarget.html) 操作，並提供 `ResourceId`、`ScalableDimension`、`ServiceNamespace`、`MinCapacity` 及 `MaxCapacity` 作為參數。

## 相關資源
<a name="elasticache-related-resources"></a>

如需詳細資訊，請參閱《*Amazon ElastiCache 使用者指南*》中的 [Auto Scaling Valkey 和 Redis OSS 叢集](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/AutoScaling.html)和 [Memcached 的 Scaling 叢集](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/Scaling-self-designed.mem-heading.html)。