

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# ElastiCache 和应用程序 Auto Scaling
<a name="services-that-can-integrate-elasticache"></a>

您可以使用目标跟踪扩展策略和计划扩展，横向扩展亚马逊 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 控制台配置 auto Scaling，则 ElastiCache 会自动为您注册可扩展目标。

如果要使用 AWS CLI 或其中一个来配置 auto Scaling AWS SDKs，则可以使用以下选项：
+ AWS CLI: 

  调用 ElastiCache复制组的[register-scalable-target](https://docs.aws.amazon.com/cli/latest/reference/application-autoscaling/register-scalable-target.html)命令。以下示例注册名为 `mycluster1` 的复制组的所需节点组数量，最小容量为一个，最大容量为 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>

有关更多信息，请参阅*亚马逊 ElastiCache *用户指南中的 [Auto Scaling Valkey 和 Redis OSS 集群](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/AutoScaling.html)[以及扩展 Memcached](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/Scaling-self-designed.mem-heading.html) 集群。