

# Configure multi-Region replication for Amazon Keyspaces (for Apache Cassandra)
<a name="multiRegion-replication-configure"></a>

You can use the console, Cassandra Query Language (CQL), or the AWS Command Line Interface to create and manage multi-Region keyspaces and tables in Amazon Keyspaces. 

This section provides examples of how to create and manage multi-Region keyspaces and tables. All tables that you create in a multi-Region keyspace automatically inherit the multi-Region settings from the keyspace. 

For more information about supported configurations and features, see [Amazon Keyspaces multi-Region replication usage notes](multiRegion-replication_usage-notes.md).

**Topics**
+ [Configure the IAM permissions required to create multi-Region keyspaces and tables](howitworks_replication_permissions.md)
+ [Configure the IAM permissions required to add an AWS Region to a keyspace](howitworks_replication_permissions_addReplica.md)
+ [Create a multi-Region keyspace in Amazon Keyspaces](keyspaces-mrr-create.md)
+ [Add an AWS Region to a keyspace in Amazon Keyspaces](keyspaces-multi-region-add-replica.md)
+ [Check the replication progress when adding a new Region to a keyspace](keyspaces-multi-region-replica-status.md)
+ [Create a multi-Region table with default settings in Amazon Keyspaces](tables-mrr-create-default.md)
+ [Create a multi-Region table in provisioned mode with auto scaling in Amazon Keyspaces](tables-mrr-create-provisioned.md)
+ [Update the provisioned capacity and auto scaling settings for a multi-Region table in Amazon Keyspaces](tables-mrr-autoscaling.md)
+ [View the provisioned capacity and auto scaling settings for a multi-Region table in Amazon Keyspaces](tables-mrr-view.md)
+ [Turn off auto scaling for a table in Amazon Keyspaces](tables-mrr-autoscaling-off.md)
+ [Set the provisioned capacity of a multi-Region table manually in Amazon Keyspaces](tables-mrr-capacity-manually.md)

# Configure the IAM permissions required to create multi-Region keyspaces and tables
<a name="howitworks_replication_permissions"></a>

To successfully create multi-Region keyspaces and tables, the IAM principal needs to be able to create a service-linked role. This service-linked role is a unique type of IAM role that is predefined by Amazon Keyspaces. It includes all the permissions that Amazon Keyspaces requires to perform actions on your behalf. For more information about the service-linked role, see [Using roles for Amazon Keyspaces Multi-Region Replication](using-service-linked-roles-multi-region-replication.md).

To create the service-linked role required by multi-Region replication, the policy for the IAM principal requires the following elements:
+ `iam:CreateServiceLinkedRole` – The **action** the principal can perform.
+ `arn:aws:iam::*:role/aws-service-role/replication.cassandra.amazonaws.com/AWSServiceRoleForKeyspacesReplication` – The **resource** that the action can be performed on. 
+ `iam:AWSServiceName": "replication.cassandra.amazonaws.com` – The only AWS service that this role can be attached to is Amazon Keyspaces.

The following is an example of the policy that grants the minimum required permissions to a principal to create multi-Region keyspaces and tables.

```
{
            "Effect": "Allow",
            "Action": "iam:CreateServiceLinkedRole",
            "Resource": "arn:aws:iam::*:role/aws-service-role/replication.cassandra.amazonaws.com/AWSServiceRoleForKeyspacesReplication",
            "Condition": {"StringLike": {"iam:AWSServiceName": "replication.cassandra.amazonaws.com"}}
}
```

For additional IAM permissions for multi-Region keyspaces and tables, see the [Actions, resources, and condition keys for Amazon Keyspaces (for Apache Cassandra)](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkeyspacesforapachecassandra.html) in the *Service Authorization Reference*.

# Configure the IAM permissions required to add an AWS Region to a keyspace
<a name="howitworks_replication_permissions_addReplica"></a>

To add a Region to a keyspace, the IAM principal needs the following permissions:
+ `cassandra:Alter`
+ `cassandra:AlterMultiRegionResource`
+ `cassandra:Create`
+ `cassandra:CreateMultiRegionResource`
+ `cassandra:Select`
+ `cassandra:SelectMultiRegionResource`
+ `cassandra:Modify`
+ `cassandra:ModifyMultiRegionResource`

If the table is configured in provisioned mode with auto scaling enabled, the following additional permissions are needed.
+ `application-autoscaling:RegisterScalableTarget`
+ `application-autoscaling:DeregisterScalableTarget`
+ `application-autoscaling:DescribeScalableTargets`
+ `application-autoscaling:PutScalingPolicy`
+ `application-autoscaling:DescribeScalingPolicies`

To successfully add a Region to a single-Region keyspace, the IAM principal also needs to be able to create a service-linked role. This service-linked role is a unique type of IAM role that is predefined by Amazon Keyspaces. It includes all the permissions that Amazon Keyspaces requires to perform actions on your behalf. For more information about the service-linked role, see [Using roles for Amazon Keyspaces Multi-Region Replication](using-service-linked-roles-multi-region-replication.md).

To create the service-linked role required by multi-Region replication, the policy for the IAM principal requires the following elements:
+ `iam:CreateServiceLinkedRole` – The **action** the principal can perform.
+ `arn:aws:iam::*:role/aws-service-role/replication.cassandra.amazonaws.com/AWSServiceRoleForKeyspacesReplication` – The **resource** that the action can be performed on. 
+ `iam:AWSServiceName": "replication.cassandra.amazonaws.com` – The only AWS service that this role can be attached to is Amazon Keyspaces.

The following is an example of the policy that grants the minimum required permissions to a principal to add a Region to a keyspace.

```
{
            "Effect": "Allow",
            "Action": "iam:CreateServiceLinkedRole",
            "Resource": "arn:aws:iam::*:role/aws-service-role/replication.cassandra.amazonaws.com/AWSServiceRoleForKeyspacesReplication",
            "Condition": {"StringLike": {"iam:AWSServiceName": "replication.cassandra.amazonaws.com"}}
}
```

# Create a multi-Region keyspace in Amazon Keyspaces
<a name="keyspaces-mrr-create"></a>

This section provides examples of how to create a multi-Region keyspace. You can do this on the Amazon Keyspaces console, using CQL or the AWS CLI. All tables that you create in a multi-Region keyspace automatically inherit the multi-Region settings from the keyspace.

**Note**  
When creating a multi-Region keyspace, Amazon Keyspaces creates a service-linked role with the name `AWSServiceRoleForAmazonKeyspacesReplication` in your account. This role allows Amazon Keyspaces to replicate writes to all replicas of a multi-Region table on your behalf. To learn more, see [Using roles for Amazon Keyspaces Multi-Region Replication](using-service-linked-roles-multi-region-replication.md).

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

**Create a multi-Region keyspace (console)**

1. Sign in to the AWS Management Console, and open the Amazon Keyspaces console at [https://console.aws.amazon.com/keyspaces/home](https://console.aws.amazon.com/keyspaces/home).

1. In the navigation pane, choose **Keyspaces**, and then choose **Create keyspace**.

1. For **Keyspace name**, enter the name for the keyspace.

1. In the **Multi-Region replication** section, you can add the additional Regions that are available in the list.

1. To finish, choose **Create keyspace**.

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

**Create a multi-Region keyspace using CQL**

1. To create a multi-Region keyspace, use `NetworkTopologyStrategy` to specify the AWS Regions that the keyspace is going to be replicated in. You must include your current Region and at least one additional Region. 

   All tables in the keyspace inherit the replication strategy from the keyspace. You can't change the replication strategy at the table level.

   `NetworkTopologyStrategy` – The replication factor for each Region is three because Amazon Keyspaces replicates data across three [Availability Zones](https://aws.amazon.com/about-aws/global-infrastructure/regions_az/) within the same AWS Region, by default. 

   The following CQL statement is an example of this.

   ```
   CREATE KEYSPACE mykeyspace
   WITH REPLICATION = {'class':'NetworkTopologyStrategy', 'us-east-1':'3', 'ap-southeast-1':'3','eu-west-1':'3' };
   ```

1. You can use a CQL statement to query the `tables` table in the `system_multiregion_info` keyspace to programmatically list the Regions and the status of the multi-Region table that you specify. The following code is an example of this.

   ```
   SELECT * from system_multiregion_info.tables WHERE keyspace_name = 'mykeyspace' AND table_name = 'mytable';
   ```

   The output of the statement looks like the following:

   ```
    keyspace_name  | table_name     | region         | status
   ----------------+----------------+----------------+--------
    mykeyspace     | mytable        | us-east-1      | ACTIVE
    mykeyspace     | mytable        | ap-southeast-1 | ACTIVE
    mykeyspace     | mytable        | eu-west-1      | ACTIVE
   ```

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

**Create a new multi-Region keyspace using the AWS CLI**
+ To create a multi-Region keyspace, you can use the following CLI statement. Specify your current Region and at least one additional Region in the `regionList`.

  ```
  aws keyspaces create-keyspace --keyspace-name mykeyspace \
  --replication-specification replicationStrategy=MULTI_REGION,regionList=us-east-1,eu-west-1
  ```

------

To create a multi-Region table, see [Create a multi-Region table with default settings in Amazon Keyspaces](tables-mrr-create-default.md) and [Create a multi-Region table in provisioned mode with auto scaling in Amazon Keyspaces](tables-mrr-create-provisioned.md).

# Add an AWS Region to a keyspace in Amazon Keyspaces
<a name="keyspaces-multi-region-add-replica"></a>

You can add a new AWS Region to a keyspace that is either a single or a multi-Region keyspace. The new replica Region is applied to all tables in the keyspace. 

To change a single-Region to a multi-Region keyspace, you have to enable client-side timestamps for all tables in the keyspace. For more information, see [Client-side timestamps in Amazon Keyspaces](client-side-timestamps.md).

If you're adding an additional Region to a multi-Region keyspace, Amazon Keyspaces has to replicate the existing table(s) into the new Region using a one-time cross-Region restore for each existing table. The restore charges for each table are billed per GB, for more information see [Backup and restore](https://aws.amazon.com/keyspaces/pricing/#:~:text=per%20GB-month-,Restoring%20a%20table,-Restoring%20a%20table) on the Amazon Keyspaces (for Apache Cassandra) pricing page. There's no charge for data transfer across Regions for this restore operation. In addition to data, all table properties with the exception of tags are going to be replicated to the new Region.

You can use the `ALTER KEYSPACE` statement in CQL, the `update-keyspace` command with the AWS CLI, or the console to add a new Region to a single or to a multi-Region keyspace in Amazon Keyspaces. In order to run the statement successfully, the account you're using has to be located in one of the Regions where the keyspace is already available. While the replica is being added, you can't perform any other data definition language (DDL) operations on the resources that are being updated and replicated.

For more information about the permissions required to add a Region, see [Configure the IAM permissions required to add an AWS Region to a keyspace](howitworks_replication_permissions_addReplica.md).

**Note**  
When adding an additional Region to a single-Region keyspace, Amazon Keyspaces creates a service-linked role with the name `AWSServiceRoleForAmazonKeyspacesReplication` in your account. This role allows Amazon Keyspaces to replicate tables to new Regions and to replicate writes from one table to all replicas of a multi-Region table on your behalf. To learn more, see [Using roles for Amazon Keyspaces Multi-Region Replication](using-service-linked-roles-multi-region-replication.md).

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

Follow these steps to add a Region to a keyspace using the Amazon Keyspaces console.

**Add a Region to a keyspace (console)**

1. Sign in to the AWS Management Console, and open the Amazon Keyspaces console at [https://console.aws.amazon.com/keyspaces/home](https://console.aws.amazon.com/keyspaces/home).

1. In the navigation pane, choose **Keyspaces**, and then choose a keyspace from the list.

1. Choose the **AWS Regions** tab.

1. On the **AWS Regions** tab, choose **Add Region**.

1. In the **Add Region** dialog, choose the additional Region that you want to add to the keyspace.

1. To finish, choose **Add**.

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

**Add a Region to a keyspace using CQL**
+ To add a new Region to a keyspace, you can use the following statement. In this example, the keyspace is already available in the US East (N. Virginia) Region and US West (Oregon) Region Regions, and the CQL statement is adding the Region US West (N. California) Region. 

  ```
  ALTER KEYSPACE my_keyspace
  WITH REPLICATION = {
      'class': 'NetworkTopologyStrategy',
      'us-east-1': '3',
      'us-west-2': '3',
      'us-west-1': '3'
  } AND CLIENT_SIDE_TIMESTAMPS = {'status': 'ENABLED'};
  ```

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

**Add a Region to a keyspace using the AWS CLI**
+ To add a new Region to a keyspace using the CLI, you can use the following example. Note that the default value for `client-side-timestamps` is `DISABLED`. With the `update-keyspace` command, you must change the value to `ENABLED`.

  ```
  aws keyspaces update-keyspace \
  --keyspace-name my_keyspace \
  --replication-specification '{"replicationStrategy": "MULTI_REGION", "regionList": ["us-east-1", "eu-west-1", "eu-west-3"] }' \
  --client-side-timestamps '{"status": "ENABLED"}'
  ```

------

# Check the replication progress when adding a new Region to a keyspace
<a name="keyspaces-multi-region-replica-status"></a>

Adding a new Region to an Amazon Keyspaces keyspace is a long running operation. To track progress you can use the queries shown in this section.

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

**Using CQL to verify the add Region progress**
+  To verify the progress of the creation of the new table replicas in a given keyspace, you can query the `system_multiregion_info.keyspaces` table. The following CQL statement is an example of this.

  ```
  SELECT keyspace_name, region, status, tables_replication_progress
  FROM system_multiregion_info.keyspaces
  WHERE keyspace_name = 'my_keyspace';
  ```

  While a replication operation is in progress, the status shows the progress of table creation in the new Region. This is an example where 5 out of 10 tables have been replicated to the new Region.

  ```
   keyspace_name | region    | status    | tables_replication_progress
  ---------------+-----------+-----------+-------------------------
     my_keyspace | us-east-1 | Updating  | 
     my_keyspace | us-west-2 | Updating  | 
     my_keyspace | eu-west-1 | Creating  | 50%
  ```

  After the replication process has completed successfully, the output should look like this example.

  ```
   keyspace_name | region    | status
  ---------------+-----------+-----------
     my_keyspace | us-east-1 | Active
     my_keyspace | us-west-2 | Active
     my_keyspace | eu-west-1 | Active
  ```

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

**Using the AWS CLI to verify the add Region progress**
+ To confirm the status of table replica creation for a given keyspace, you can use the following example.

  ```
  aws keyspaces get-keyspace \
  --keyspace-name my_keyspace
  ```

  The output should look similar to this example.

  ```
  {
      "keyspaceName": "my_keyspace",
      "resourceArn": "arn:aws:cassandra:us-east-1:111122223333:/keyspace/my_keyspace/",
      "replicationStrategy": "MULTI_REGION",
      "replicationRegions": [
          "us-east-1",
          "eu-west-1"
      ]
      "replicationGroupStatus": [
          {
              "RegionName": "us-east-1",
              "KeyspaceStatus": "Active"
          },
          {
              "RegionName": "eu-west-1",
              "KeyspaceStatus": "Creating",
              "TablesReplicationProgress": "50.0%"
          }
      ]
  }
  ```

------

# Create a multi-Region table with default settings in Amazon Keyspaces
<a name="tables-mrr-create-default"></a>

This section provides examples of how to create a multi-Region table in on-demand mode with all default settings. You can do this on the Amazon Keyspaces console, using CQL or the AWS CLI. All tables that you create in a multi-Region keyspace automatically inherit the multi-Region settings from the keyspace.

To create a multi-Region keyspace, see [Create a multi-Region keyspace in Amazon Keyspaces](keyspaces-mrr-create.md).

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

**Create a multi-Region table with default settings (console)**

1. Sign in to the AWS Management Console, and open the Amazon Keyspaces console at [https://console.aws.amazon.com/keyspaces/home](https://console.aws.amazon.com/keyspaces/home).

1. Choose a multi-Region keyspace.

1. On the **Tables** tab, choose **Create table**.

1. For **Table name**, enter the name for the table. The AWS Regions that this table is being replicated in are shown in the info box.

1. Continue with the table schema.

1. Under **Table settings**, continue with the **Default settings** option. Note the following default settings for multi-Region tables.
   + **Capacity mode** – The default capacity mode is **On-demand**. For more information about configuring **provisioned** mode, see [Create a multi-Region table in provisioned mode with auto scaling in Amazon Keyspaces](tables-mrr-create-provisioned.md).
   + **Encryption key management** – Only the **AWS owned key** option is supported.
   + **Client-side timestamps** – This feature is required for multi-Region tables.
   + Choose **Customize settings** if you need to turn on Time to Live (TTL) for the table and all its replicas.
**Note**  
You won't be able to change TTL settings on an existing multi-Region table.

1. To finish, choose **Create table**.

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

**Create a multi-Region table in on-demand mode with default settings**
+ To create a multi-Region table with default settings, you can use the following CQL statement.

  ```
  CREATE TABLE mykeyspace.mytable(pk int, ck int, PRIMARY KEY (pk, ck))
      WITH CUSTOM_PROPERTIES = {
  	'capacity_mode':{
  		'throughput_mode':'PAY_PER_REQUEST'
  	},
  	'point_in_time_recovery':{
  		'status':'enabled'
  	},
  	'encryption_specification':{
  		'encryption_type':'AWS_OWNED_KMS_KEY'
  	},
  	'client_side_timestamps':{
  		'status':'enabled'
  	}
  };
  ```

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

**Using the AWS CLI**

1. To create a multi-Region table with default settings, you only need to specify the schema. You can use the following example.

   ```
   aws keyspaces create-table --keyspace-name mykeyspace --table-name mytable \
   --schema-definition 'allColumns=[{name=pk,type=int}],partitionKeys={name= pk}'
   ```

   The output of the command is:

   ```
   {
       "resourceArn": "arn:aws:cassandra:us-east-1:111122223333:/keyspace/mykeyspace/table/mytable"
   }
   ```

1. To confirm the table's settings, you can use the following statement.

   ```
   aws keyspaces get-table --keyspace-name mykeyspace --table-name mytable
   ```

   The output shows all default settings of a multi-Region table. 

   ```
   {
       "keyspaceName": "mykeyspace",
       "tableName": "mytable",
       "resourceArn": "arn:aws:cassandra:us-east-1:111122223333:/keyspace/mykeyspace/table/mytable",
       "creationTimestamp": "2023-12-19T16:50:37.639000+00:00",
       "status": "ACTIVE",
       "schemaDefinition": {
           "allColumns": [
               {
                   "name": "pk",
                   "type": "int"
               }
           ],
           "partitionKeys": [
               {
                   "name": "pk"
               }
           ],
           "clusteringKeys": [],
           "staticColumns": []
       },
       "capacitySpecification": {
           "throughputMode": "PAY_PER_REQUEST",
           "lastUpdateToPayPerRequestTimestamp": "2023-12-19T16:50:37.639000+00:00"
       },
       "encryptionSpecification": {
           "type": "AWS_OWNED_KMS_KEY"
       },
       "pointInTimeRecovery": {
           "status": "DISABLED"
       },
       "defaultTimeToLive": 0,
       "comment": {
           "message": ""
       },
       "clientSideTimestamps": {
           "status": "ENABLED"
       },
       "replicaSpecifications": [
           {
               "region": "us-east-1",
               "status": "ACTIVE",
               "capacitySpecification": {
                   "throughputMode": "PAY_PER_REQUEST",
                   "lastUpdateToPayPerRequestTimestamp": 1702895811.469
               }
           },
           {
               "region": "eu-north-1",
               "status": "ACTIVE",
               "capacitySpecification": {
                   "throughputMode": "PAY_PER_REQUEST",
                   "lastUpdateToPayPerRequestTimestamp": 1702895811.121
               }
           }
       ]
   }
   ```

------

# Create a multi-Region table in provisioned mode with auto scaling in Amazon Keyspaces
<a name="tables-mrr-create-provisioned"></a>

This section provides examples of how to create a multi-Region table in provisioned mode with auto scaling. You can do this on the Amazon Keyspaces console, using CQL or the AWS CLI. 

For more information about supported configurations and multi-Region replication features, see [Amazon Keyspaces multi-Region replication usage notes](multiRegion-replication_usage-notes.md).

To create a multi-Region keyspace, see [Create a multi-Region keyspace in Amazon Keyspaces](keyspaces-mrr-create.md).

When you create a new multi-Region table in provisioned mode with auto scaling settings, you can specify the general settings for the table that are valid for all AWS Regions that the table is replicated in. You can then overwrite read capacity settings and read auto scaling settings for each replica. The write capacity, however, remains synchronized between all replicas to ensure that there's enough capacity to replicate writes across all Regions. 

**Note**  
Amazon Keyspaces automatic scaling requires the presence of a service-linked role (`AWSServiceRoleForApplicationAutoScaling_CassandraTable`) that performs automatic scaling actions on your behalf. This role is created automatically for you. For more information, see [Using service-linked roles for Amazon Keyspaces](using-service-linked-roles.md).

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

**Create a new multi-Region table with automatic scaling enabled**

1. Sign in to the AWS Management Console, and open the Amazon Keyspaces console at [https://console.aws.amazon.com/keyspaces/home](https://console.aws.amazon.com/keyspaces/home).

1. Choose a multi-Region keyspace.

1. On the **Tables** tab, choose **Create table**.

1. On the **Create table** page in the **Table details** section, select a keyspace and provide a name for the new table.

1. In the **Columns** section, create the schema for your table.

1. In the **Primary key** section, define the primary key of the table and select optional clustering columns.

1. In the **Table settings** section, choose **Customize settings**.

1. Continue to **Read/write capacity settings**.

1. For **Capacity mode**, choose **Provisioned**.

1. In the **Read capacity** section, confirm that **Scale automatically** is selected.

   You can select to configure the same read capacity units for all AWS Regions that the table is replicated in. Alternatively, you can clear the check box and configure the read capacity for each Region differently.

   If you choose to configure each Region differently, you select the minimum and maximum read capacity units for each table replica, as well as the target utilization.
   + **Minimum capacity units** – Enter the value for the minimum level of throughput that the table should always be ready to support. The value must be between 1 and the maximum throughput per second quota for your account (40,000 by default).
   + **Maximum capacity units** – Enter the maximum amount of throughput that you want to provision for the table. The value must be between 1 and the maximum throughput per second quota for your account (40,000 by default).
   + **Target utilization** – Enter a target utilization rate between 20% and 90%. When traffic exceeds the defined target utilization rate, capacity is automatically scaled up. When traffic falls below the defined target, it is automatically scaled down again.
   + Clear the **Scale automatically** check box if you want to provision the table's read capacity manually. This setting applies to all replicas of the table.
**Note**  
To ensure that there's enough read capacity for all replicas, we recommend Amazon Keyspaces automatic scaling for provisioned multi-Region tables.
**Note**  
To learn more about default quotas for your account and how to increase them, see [Quotas for Amazon Keyspaces (for Apache Cassandra)](quotas.md).

1. In the **Write capacity** section, confirm that **Scale automatically** is selected. Then configure the capacity units for the table. The write capacity units stay synced across all AWS Regions to ensure that there is enough capacity to replicate write events across the Regions.
   + Clear **Scale automatically** if you want to provision the table's write capacity manually. This setting applies to all replicas of the table.
**Note**  
To ensure that there's enough write capacity for all replicas, we recommend Amazon Keyspaces automatic scaling for provisioned multi-Region tables.

1. Choose **Create table**. Your table is created with the specified automatic scaling parameters.

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

**Create a multi-Region table with provisioned capacity mode and auto scaling using CQL**
+ To create a multi-Region table in provisioned mode with auto scaling, you must first specify the capacity mode by defining `CUSTOM_PROPERTIES` for the table. After specifying provisioned capacity mode, you can configure the auto scaling settings for the table using `AUTOSCALING_SETTINGS`. 

  For detailed information about auto scaling settings, the target tracking policy, target value, and optional settings, see [Create a new table with automatic scaling](autoscaling.createTable.md).

  To define the read capacity for a table replica in a specific Region, you can configure the following parameters as part of the table's `replica_updates`:
  + The Region
  + The provisioned read capacity units (optional)
  + Auto scaling settings for read capacity (optional)

  The following example shows a `CREATE TABLE` statement for a multi-Region table in provisioned mode. The general write and read capacity auto scaling settings are the same. However, the read auto scaling settings specify additional cooldown periods of 60 seconds before scaling the table's read capacity up or down. In addition, the read capacity auto scaling settings for the Region US East (N. Virginia) are higher than those for other replicas. Also, the target value is set to 70% instead of 50%.

  ```
  CREATE TABLE mykeyspace.mytable(pk int, ck int, PRIMARY KEY (pk, ck))
  WITH CUSTOM_PROPERTIES = {  
      'capacity_mode': {  
          'throughput_mode': 'PROVISIONED',  
          'read_capacity_units': 5,  
          'write_capacity_units': 5  
      }
  } 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
              }  
          }  
      },
      'replica_updates': {
          'us-east-1': {
              'provisioned_read_capacity_autoscaling_update': {
                  'maximum_units': 20,
                  'minimum_units': 5,
                  'scaling_policy': {
                      'target_tracking_scaling_policy_configuration': {
                          'target_value': 70
                      } 
                  }
              }
          }
      }
  };
  ```

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

**Create a new multi-Region table in provisioned mode with auto scaling using the AWS CLI**
+ To create a multi-Region table in provisioned mode with auto scaling configuration, you can use the AWS CLI. Note that you must use the Amazon Keyspaces CLI `create-table` command to configure multi-Region auto scaling settings. This is because Application Auto Scaling, the service that Amazon Keyspaces uses to perform auto scaling on your behalf, doesn't support multiple Regions. 

  For more information about auto scaling settings, the target tracking policy, target value, and optional settings, see [Create a new table with automatic scaling](autoscaling.createTable.md).

  To define the read capacity for a table replica in a specific Region, you can configure the following parameters as part of the table's `replicaSpecifications`:
  + The Region
  + The provisioned read capacity units (optional)
  + Auto scaling settings for read capacity (optional)

  When you're creating provisioned multi-Region tables with complex auto scaling settings and different configurations for table replicas, it's helpful to load the table's auto scaling settings and replica configurations from JSON files. 

  To use the following code example, you can download the example JSON files from [auto-scaling.zip](samples/auto-scaling.zip), and extract `auto-scaling.json` and `replication.json`. Take note of the path to the files. 

  In this example, the JSON files are located in the current directory. For different file path options, see [ How to load parameters from a file](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters-file.html#cli-usage-parameters-file-how).

  ```
  aws keyspaces create-table --keyspace-name mykeyspace --table-name mytable \
  --schema-definition 'allColumns=[{name=pk,type=int},{name=ck,type=int}],partitionKeys=[{name=pk},{name=ck}]' \
  --capacity-specification throughputMode=PROVISIONED,readCapacityUnits=1,writeCapacityUnits=1 \
  --auto-scaling-specification file://auto-scaling.json \
  --replica-specifications file://replication.json
  ```

------

# Update the provisioned capacity and auto scaling settings for a multi-Region table in Amazon Keyspaces
<a name="tables-mrr-autoscaling"></a>

This section includes examples of how to use the console, CQL, and the AWS CLI to manage the Amazon Keyspaces auto scaling settings of provisioned multi-Region tables. For more information about general auto scaling configuration options and how they work, see [Manage throughput capacity automatically with Amazon Keyspaces auto scaling](autoscaling.md). 

Note that if you're using provisioned capacity mode for multi-Region tables, you must always use Amazon Keyspaces API calls to configure auto scaling. This is because the underlying Application Auto Scaling API operations are not Region-aware.

For more information on how to estimate write capacity throughput of provisioned multi-Region tables, see [Estimate and provision capacity for a multi-Region table in Amazon Keyspaces](tables-multi-region-capacity.md).

For more information about the Amazon Keyspaces API, see [https://docs.aws.amazon.com/keyspaces/latest/APIReference/Welcome.html](https://docs.aws.amazon.com/keyspaces/latest/APIReference/Welcome.html).

When you update the provisioned mode or auto scaling settings of a multi-Region table, you can update read capacity settings and the read auto scaling configuration for each replica of the table. 

The write capacity, however, remains synchronized between all replicas to ensure that there's enough capacity to replicate writes across all Regions.

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

**Update the provisioned capacity and auto scaling settings of a multi-Region table using CQL**
+  You can use `ALTER TABLE` to update the capacity mode and auto scaling settings of an existing table. If you're updating a table that is currently in on-demand capacity mode, `capacity_mode` is required. If your table is already in provisioned capacity mode, this field can be omitted. 

  For detailed information about auto scaling settings, the target tracking policy, target value, and optional settings, see [Create a new table with automatic scaling](autoscaling.createTable.md). 

  In the same statement, you can also update the read capacity and auto scaling settings of table replicas in specific Regions by updating the table's `replica_updates` property. The following statement is an example of this.

  ```
  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
              }  
          }  
      },
      'replica_updates': {
          'us-east-1': {
              'provisioned_read_capacity_autoscaling_update': {
                  'maximum_units': 20,
                  'minimum_units': 5,
                  'scaling_policy': {
                      'target_tracking_scaling_policy_configuration': {
                          'target_value': 70
                      } 
                  }
              }
          }
      }
  };
  ```

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

**Update the provisioned capacity and auto scaling settings of a multi-Region table using the AWS CLI**
+ To update the provisioned mode and auto scaling configuration of an existing table, you can use the AWS CLI `update-table` command. 

  Note that you must use the Amazon Keyspaces CLI commands to create or modify multi-Region auto scaling settings. This is because Application Auto Scaling, the service that Amazon Keyspaces uses to perform auto scaling of table capacity on your behalf, doesn't support multiple AWS Regions. 

   To update the read capacity for a table replica in a specific Region, you can change one of the following optional parameters of the table's `replicaSpecifications`:
  + The provisioned read capacity units (optional)
  + Auto scaling settings for read capacity (optional)

  When you're updating multi-Region tables with complex auto scaling settings and different configurations for table replicas, it's helpful to load the table's auto scaling settings and replica configurations from JSON files. 

  To use the following code example, you can download the example JSON files from [auto-scaling.zip](samples/auto-scaling.zip), and extract `auto-scaling.json` and `replication.json`. Take note of the path to the files. 

  In this example, the JSON files are located in the current directory. For different file path options, see [ How to load parameters from a file](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters-file.html#cli-usage-parameters-file-how).

  ```
  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 \
  --replica-specifications file://replication.json
  ```

------

# View the provisioned capacity and auto scaling settings for a multi-Region table in Amazon Keyspaces
<a name="tables-mrr-view"></a>

You can view a multi-Region table's provisioned capacity and auto scaling settings on the Amazon Keyspaces console, using CQL, or the AWS CLI. This section provides examples of how to do this using CQL and the AWS CLI. 

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

**View the provisioned capacity and auto scaling settings of a multi-Region table using CQL**
+ To view the auto scaling configuration of a multi-Region table, use the following command.

  ```
  SELECT * FROM system_multiregion_info.autoscaling WHERE keyspace_name = 'mykeyspace' AND table_name = 'mytable';
  ```

  The output for this command looks like the following:

  ```
   keyspace_name  | table_name | region         | provisioned_read_capacity_autoscaling_update                                                                                                                                                                      | provisioned_write_capacity_autoscaling_update
  ----------------+------------+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    mykeyspace    |  mytable   | ap-southeast-1 | {'minimum_units': 5, 'maximum_units': 10, 'scaling_policy': {'target_tracking_scaling_policy_configuration': {'scale_out_cooldown': 60, 'disable_scale_in': false, 'target_value': 50, 'scale_in_cooldown': 60}}} | {'minimum_units': 5, 'maximum_units': 10, 'scaling_policy': {'target_tracking_scaling_policy_configuration': {'scale_out_cooldown': 0, 'disable_scale_in': false, 'target_value': 50, 'scale_in_cooldown': 0}}}
    mykeyspace    |  mytable   | us-east-1      | {'minimum_units': 5, 'maximum_units': 20, 'scaling_policy': {'target_tracking_scaling_policy_configuration': {'scale_out_cooldown': 60, 'disable_scale_in': false, 'target_value': 70, 'scale_in_cooldown': 60}}} | {'minimum_units': 5, 'maximum_units': 10, 'scaling_policy': {'target_tracking_scaling_policy_configuration': {'scale_out_cooldown': 0, 'disable_scale_in': false, 'target_value': 50, 'scale_in_cooldown': 0}}}
    mykeyspace    |  mytable   | eu-west-1      | {'minimum_units': 5, 'maximum_units': 10, 'scaling_policy': {'target_tracking_scaling_policy_configuration': {'scale_out_cooldown': 60, 'disable_scale_in': false, 'target_value': 50, 'scale_in_cooldown': 60}}} | {'minimum_units': 5, 'maximum_units': 10, 'scaling_policy': {'target_tracking_scaling_policy_configuration': {'scale_out_cooldown': 0, 'disable_scale_in': false, 'target_value': 50, 'scale_in_cooldown': 0}}}
  ```

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

**View the provisioned capacity and auto scaling settings of a multi-Region table using the AWS CLI**
+ To view the auto scaling configuration of a multi-Region table, you can use the `get-table-auto-scaling-settings` operation. The following CLI command is an example of this.

  ```
  aws keyspaces get-table-auto-scaling-settings --keyspace-name mykeyspace --table-name mytable
  ```

  You should see the following output.

  ```
  {
      "keyspaceName": "mykeyspace",
      "tableName": "mytable",
      "resourceArn": "arn:aws:cassandra:us-east-1:777788889999:/keyspace/mykeyspace/table/mytable",
      "autoScalingSpecification": {
          "writeCapacityAutoScaling": {
              "autoScalingDisabled": false,
              "minimumUnits": 5,
              "maximumUnits": 10,
              "scalingPolicy": {
                  "targetTrackingScalingPolicyConfiguration": {
                      "disableScaleIn": false,
                      "scaleInCooldown": 0,
                      "scaleOutCooldown": 0,
                      "targetValue": 50.0
                  }
              }
          },
          "readCapacityAutoScaling": {
              "autoScalingDisabled": false,
              "minimumUnits": 5,
              "maximumUnits": 20,
              "scalingPolicy": {
                  "targetTrackingScalingPolicyConfiguration": {
                      "disableScaleIn": false,
                      "scaleInCooldown": 60,
                      "scaleOutCooldown": 60,
                      "targetValue": 70.0
                  }
              }
          }
      },
      "replicaSpecifications": [
          {
              "region": "us-east-1",
              "autoScalingSpecification": {
                  "writeCapacityAutoScaling": {
                      "autoScalingDisabled": false,
                      "minimumUnits": 5,
                      "maximumUnits": 10,
                      "scalingPolicy": {
                          "targetTrackingScalingPolicyConfiguration": {
                              "disableScaleIn": false,
                              "scaleInCooldown": 0,
                              "scaleOutCooldown": 0,
                              "targetValue": 50.0
                          }
                      }
                  },
                  "readCapacityAutoScaling": {
                      "autoScalingDisabled": false,
                      "minimumUnits": 5,
                      "maximumUnits": 20,
                      "scalingPolicy": {
                          "targetTrackingScalingPolicyConfiguration": {
                              "disableScaleIn": false,
                              "scaleInCooldown": 60,
                              "scaleOutCooldown": 60,
                              "targetValue": 70.0
                          }
                      }
                  }
              }
          },
          {
              "region": "eu-north-1",
              "autoScalingSpecification": {
                  "writeCapacityAutoScaling": {
                      "autoScalingDisabled": false,
                      "minimumUnits": 5,
                      "maximumUnits": 10,
                      "scalingPolicy": {
                          "targetTrackingScalingPolicyConfiguration": {
                              "disableScaleIn": false,
                              "scaleInCooldown": 0,
                              "scaleOutCooldown": 0,
                              "targetValue": 50.0
                          }
                      }
                  },
                  "readCapacityAutoScaling": {
                      "autoScalingDisabled": false,
                      "minimumUnits": 5,
                      "maximumUnits": 10,
                      "scalingPolicy": {
                          "targetTrackingScalingPolicyConfiguration": {
                              "disableScaleIn": false,
                              "scaleInCooldown": 60,
                              "scaleOutCooldown": 60,
                              "targetValue": 50.0
                          }
                      }
                  }
              }
          }
      ]
  }
  ```

------

# Turn off auto scaling for a table in Amazon Keyspaces
<a name="tables-mrr-autoscaling-off"></a>

This section provides examples of how to turn off auto scaling for a multi-Region table in provisioned capacity mode. You can do this on the Amazon Keyspaces console, using CQL or the AWS CLI. 

**Important**  
We recommend using auto scaling for multi-Region tables that use provisioned capacity mode. For more information, see [Estimate and provision capacity for a multi-Region table in Amazon Keyspaces](tables-multi-region-capacity.md).

**Note**  
To delete the service-linked role that Application Auto Scaling uses, you must disable automatic scaling on all tables in the account across all AWS Regions.

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

**Turn off Amazon Keyspaces automatic scaling for an existing multi-Region table on the console**

1. Sign in to the AWS Management Console, and open the Amazon Keyspaces console at [https://console.aws.amazon.com/keyspaces/home](https://console.aws.amazon.com/keyspaces/home).

1. Choose the table that you want to work with and choose the **Capacity** tab.

1. In the **Capacity settings** section, choose **Edit**.

1. To disable Amazon Keyspaces automatic scaling, clear the **Scale automatically** check box. Disabling automatic scaling deregisters the table as a scalable target with Application Auto Scaling. To delete the service-linked role that Application Auto Scaling uses to access your Amazon Keyspaces table, follow the steps in [Deleting a service-linked role for Amazon Keyspaces](using-service-linked-roles-app-auto-scaling.md#delete-service-linked-role-app-auto-scaling). 

1. When the automatic scaling settings are defined, choose **Save**.

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

**Turn off auto scaling for a multi-Region table using CQL**
+  You can use `ALTER TABLE` to turn off auto scaling for an existing table. Note that you can't turn off auto scaling for an individual table replica.

  In the following example, auto scaling is turned off for the table's read capacity.

  ```
  ALTER TABLE mykeyspace.mytable
  WITH AUTOSCALING_SETTINGS = {
      'provisioned_read_capacity_autoscaling_update': {
          'autoscaling_disabled': true
      }
  };
  ```

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

**Turn off auto scaling for a multi-Region table using the AWS CLI**
+  You can use the AWS CLI `update-table` command to turn off auto scaling for an existing table. Note that you can't turn off auto scaling for an individual table replica. 

  In the following example, auto scaling is turned off for the table's read capacity.

  ```
  aws keyspaces update-table --keyspace-name mykeyspace --table-name mytable 
             \ --auto-scaling-specification readCapacityAutoScaling={autoScalingDisabled=true}
  ```

------

# Set the provisioned capacity of a multi-Region table manually in Amazon Keyspaces
<a name="tables-mrr-capacity-manually"></a>

If you have to turn off auto scaling for a multi-Region table, you can provision the table's read capacity for a replica table manually using CQL or the AWS CLI. 

**Note**  
We recommend using auto scaling for multi-Region tables that use provisioned capacity mode. For more information, see [Estimate and provision capacity for a multi-Region table in Amazon Keyspaces](tables-multi-region-capacity.md).

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

**Setting the provisioned capacity of a multi-Region table manually using CQL**
+ You can use `ALTER TABLE` to provision the table's read capacity for a replica table manually.

  ```
  ALTER TABLE mykeyspace.mytable
  WITH CUSTOM_PROPERTIES = {  
      'capacity_mode': {  
          'throughput_mode': 'PROVISIONED',  
          'read_capacity_units': 1,  
          'write_capacity_units': 1  
      },
      'replica_updates': {
          'us-east-1': {
              'read_capacity_units': 2
           }
      }
  };
  ```

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

**Set the provisioned capacity of a multi-Region table manually using the AWS CLI**
+ If you have to turn off auto scaling for a multi-Region table, you can use `update-table` to provision the table's read capacity for a replica table manually.

  ```
  aws keyspaces update-table --keyspace-name mykeyspace --table-name mytable \
  --capacity-specification throughputMode=PROVISIONED,readCapacityUnits=1,writeCapacityUnits=1 \
  --replica-specifications region="us-east-1",readCapacityUnits=5
  ```

------