

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

# 在现有表上配置自动扩缩
<a name="autoscaling.configureTable"></a>

您可以更新现有 Amazon Keyspaces 表，为表的写入或读取容量开启自动扩缩功能。如果您要更新当前处于按需容量模式的表，则必须先将表的容量模式更改为预置容量模式。

有关如何更新多区域表的自动扩缩设置的更多信息，请参阅[在 Amazon Keyspaces 中更新多区域表的预置容量和自动扩缩设置](tables-mrr-autoscaling.md)。

Amazon Keyspaces 自动扩缩需要存在一个代表您执行自动扩缩操作的服务相关角色 (`AWSServiceRoleForApplicationAutoScaling_CassandraTable`)。将自动为您创建此角色。有关更多信息，请参阅 [对 Amazon Keyspaces 使用服务相关角色](using-service-linked-roles.md)。

------
#### [ Console ]

**为现有表配置 Amazon Keyspaces 自动扩缩**

1. [登录并在家中打开 Amazon Keyspaces 控制台。 AWS 管理控制台 https://console.aws.amazon.com/keyspaces/](https://console.aws.amazon.com/keyspaces/home)

1. 选择要处理的表，然后转到**容量**选项卡。

1. 在**容量设置**部分中，选择**编辑**。

1. 在**容量模式**下，确保表使用**预置**容量模式。

1. 选择**自动扩展**，然后按照[创建启用了自动扩缩的新表](autoscaling.createTable.md)中的步骤 6 操作来编辑读取和写入容量。

1. 在定义自动扩展设置时，选择 **Save (保存)**。

------
#### [ Cassandra Query Language (CQL) ]

**使用 CQL 配置启用 Amazon Keyspaces 自动扩缩的现有表**

您可以使用现有 Amazon Keyspaces 表的 `ALTER TABLE` 语句为表的写入或读取容量配置自动扩缩。如果您要更新当前处于按需容量模式的表，则必须将 `capacity_mode` 设置为预置模式。如果您的表已经处于预置容量模式，则可以忽略此字段。

在以下示例中，该语句更新了处于按需容量模式的表 *mytable*。该语句将表的容量模式更改为启用自动扩缩的预置模式。

写入容量配置为 5 到 10 个容量单位，目标值为 50%。读取容量也配置为 5 到 10 个容量单位，目标值为 50%。对于读取容量，您可以将 `scale_out_cooldown` 和 `scale_in_cooldown` 值设置为 60 秒。

```
ALTER TABLE mykeyspace.mytable
WITH CUSTOM_PROPERTIES = {  
    'capacity_mode': {  
        'throughput_mode': 'PROVISIONED',  
        'read_capacity_units': 1,  
        'write_capacity_units': 1  
    }
} AND AUTOSCALING_SETTINGS = {
    'provisioned_write_capacity_autoscaling_update': {
        'maximum_units': 10,  
        'minimum_units': 5,  
        'scaling_policy': {
            'target_tracking_scaling_policy_configuration': {
                'target_value': 50
            }  
        }  
    },
    'provisioned_read_capacity_autoscaling_update': {  
        'maximum_units': 10,  
        'minimum_units': 5,  
        'scaling_policy': {  
            'target_tracking_scaling_policy_configuration': {  
                'target_value': 50,
                'scale_in_cooldown': 60,  
                'scale_out_cooldown': 60
            }  
        }  
    }
};
```

------
#### [ CLI ]

**使用 Amazon Keyspaces 自动缩放配置现有表 AWS CLI**

对于现有 Amazon Keyspaces 表，您可以使用 `UpdateTable` 操作为表的写入或读取容量开启自动扩缩功能。

您可以使用以下命令为现有表开启 Amazon Keyspaces 自动扩缩。表的自动扩缩设置从 JSON 文件加载。对于下面的示例，您可以从 [auto-scaling.zip](samples/auto-scaling.zip) 下载示例 JSON 文件并提取 `auto-scaling.json`，记下文件路径。在本示例中，JSON 文件位于当前目录下。有关不同的文件路径选项，请参阅[如何从文件加载参数](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters-file.html#cli-usage-parameters-file-how)。

有关以下示例中所用的自动扩缩设置的更多信息，请参阅[创建启用了自动扩缩的新表](autoscaling.createTable.md)。

```
aws keyspaces update-table --keyspace-name mykeyspace --table-name mytable 
            \ --capacity-specification throughputMode=PROVISIONED,readCapacityUnits=1,writeCapacityUnits=1 
            \ --auto-scaling-specification file://auto-scaling.json
```

------