

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

# 注册可扩展目标
<a name="AutoScaling-Scaling-Registering-Policy-CLI"></a>

在 ElastiCache for Valkey and Redis OSS 集群上使用自动扩缩之前，您必须先为集群注册 ElastiCache 自动扩缩。这样做是为了定义应用于该集群的扩展维度和限制。ElastiCache 自动扩缩会连同 `elasticache:replication-group:NodeGroups` 可扩展维度一起动态扩缩集群，该维度表示每个集群分片的数量。

 **使用 AWS CLI** 

要注册您的 ElastiCache for Valkey and Redis OSS 集群，请使用具有以下参数的 [register-scalable-target](https://docs.aws.amazon.com/cli/latest/reference/application-autoscaling/register-scalable-target.html) 命令：
+ `--service-namespace` – 将该值设置为 `elasticache`
+ `--resource-id` – 集群的资源标识符。对于该参数，资源类型为 `ReplicationGroup`，唯一标识符为集群的名称，例如 `replication-group/myscalablecluster`。
+ `--scalable-dimension` – 将该值设置为 `elasticache:replication-group:NodeGroups`。
+ `--max-capacity ` – 由 ElastiCache 自动扩缩管理的最大分片数。有关 `--min-capacity`、`--max-capacity` 和集群中分区数之间关系的信息，请参阅 [最小和最大容量](AutoScaling-Policies.md#AutoScaling-MinMax)。
+ `--min-capacity ` – 由 ElastiCache 自动扩缩管理的最小分片数。有关 `--min-capacity`、`--max-capacity` 和集群中分区数之间关系的信息，请参阅 [最小和最大容量](AutoScaling-Policies.md#AutoScaling-MinMax)。

**Example**  
 在以下示例中，您注册一个名为 `myscalablecluster` 的 ElastiCache 集群。该注册表示应将集群动态扩展为具有 1 到 10 个分区。  
对于 Linux、macOS 或 Unix：  

```
aws application-autoscaling register-scalable-target \
    --service-namespace elasticache \
    --resource-id replication-group/myscalablecluster \
    --scalable-dimension elasticache:replication-group:NodeGroups \
    --min-capacity 1 \
    --max-capacity 10 \
```
对于 Windows：  

```
aws application-autoscaling register-scalable-target ^
    --service-namespace elasticache ^
    --resource-id replication-group/myscalablecluster ^
    --scalable-dimension elasticache:replication-group:NodeGroups ^
    --min-capacity 1 ^
    --max-capacity 10 ^
```

**使用 API**

要注册您的 ElastiCache 集群，请使用包含下列参数的 [register-scalable-target](https://docs.aws.amazon.com/cli/latest/reference/application-autoscaling/register-scalable-target.html) 命令：
+ ServiceNamespace – 将此值设置为 elasticache。
+ ResourceID – ElastiCache 集群的资源标识符。对于该参数，资源类型为 ReplicationGroup，唯一标识符为集群的名称，例如 `replication-group/myscalablecluster`。
+ ScalableDimension – 将此值设置为 `elasticache:replication-group:NodeGroups`。
+ MinCapacity – 由 ElastiCache 自动扩缩管理的最小分片数。有关 --min-capacity、--max-capacity 和集群中副本数之间关系的信息，请参阅 [最小和最大容量](AutoScaling-Policies.md#AutoScaling-MinMax)。
+ MaxCapacity – 由 ElastiCache 自动扩缩管理的最大分片数。有关 --min-capacity、--max-capacity 和集群中副本数之间关系的信息，请参阅 [最小和最大容量](AutoScaling-Policies.md#AutoScaling-MinMax)。

**Example**  
在以下示例中，您使用 Application Auto Scaling API 注册一个名为 `myscalablecluster` 的 ElastiCache 集群。该注册表示应将集群动态扩展为具有 1 到 5 个副本。  

```
POST / HTTP/1.1
Host: autoscaling.us-east-2.amazonaws.com
Accept-Encoding: identity
Content-Length: 219
X-Amz-Target: AnyScaleFrontendService.RegisterScalableTarget
X-Amz-Date: 20160506T182145Z
User-Agent: aws-cli/1.10.23 Python/2.7.11 Darwin/15.4.0 botocore/1.4.8
Content-Type: application/x-amz-json-1.1
Authorization: AUTHPARAMS
{
    "ServiceNamespace": "elasticache",
    "ResourceId": "replication-group/myscalablecluster",
    "ScalableDimension": "elasticache:replication-group:NodeGroups",
    "MinCapacity": 1,
    "MaxCapacity": 5
}
```