

# Using global datastores (CLI)
<a name="Redis-Global-Datastores-CLI"></a>

You can use the Amazon Command Line Interface (Amazon CLI) to control multiple Amazon services from the command line and automate them through scripts. You can use the Amazon CLI for ad hoc (one-time) operations. 

## Downloading and configuring the Amazon CLI
<a name="Redis-Global-Datastores-Downloading-CLI"></a>

The Amazon CLI runs on Windows, macOS, or Linux. Use the following procedure to download and configure it.

**To download, install, and configure the CLI**

1. Download the Amazon CLI on the [Amazon command line interface](http://aws.amazon.com/cli) webpage.

1. Follow the instructions for Installing the Amazon CLI and Configuring the Amazon CLI in the *Amazon Command Line Interface User Guide*.

## Using the Amazon CLI with global datastores
<a name="Redis-Global-Datastores-Using-CLI"></a>

Use the following CLI operations to work with global datastores: 
+ [create-global-replication-group](https://docs.amazonaws.cn/cli/latest/reference/elasticache/create-global-replication-group.html)

  ```
  aws elasticache create-global-replication-group \
     --global-replication-group-id-suffix {{my global datastore }} \
     --primary-replication-group-id {{sample-repl-group }} \
     --global-replication-group-description {{an optional description of the global datastore }}
  ```

  Amazon ElastiCache automatically applies a prefix to the global datastore ID when it is created. Each Amazon Region has its own prefix. For instance, a global datastore ID created in the US West (N. California) Region begins with "virxk" along with the suffix name that you provide. The suffix, combined with the autogenerated prefix, guarantees uniqueness of the global datastore name across multiple Regions. 

  The following table lists each Amazon Region and its global datastore ID prefix.

    
****    
[See the AWS documentation website for more details](http://docs.amazonaws.cn/en_us/AmazonElastiCache/latest/dg/Redis-Global-Datastores-CLI.html)
+  [create-replication-group](https://docs.amazonaws.cn/cli/latest/reference/elasticache/create-replication-group.html) – Use this operation to create secondary clusters for a global datastore by supplying the name of the global datastore to the `--global-replication-group-id` parameter.

  ```
  aws elasticache create-replication-group \
    --replication-group-id {{secondary replication group name}} \
    --replication-group-description {{“Replication group description"}} \
    --global-replication-group-id {{global datastore name}}
  ```

  When calling this operation and passing in a `--global-replication-group-id` value, ElastiCache will infer the values from the primary replication group of the global replication group for the following paramaeters. Do not pass in values for these parameters:

  `"PrimaryClusterId",`

  `"AutomaticFailoverEnabled",`

  ` "NumNodeGroups",`

  ` "CacheParameterGroupName",`

  ` "CacheNodeType",`

  ` "Engine",`

  ` "EngineVersion",`

  ` "CacheSecurityGroupNames",`

  ` "EnableTransitEncryption",`

  ` "AtRestEncryptionEnabled",`

  ` "SnapshotArns",`

  ` "SnapshotName"`
+ [describe-global-replication-groups](https://docs.amazonaws.cn/cli/latest/reference/elasticache/describe-global-replication-groups.html)

  ```
  aws elasticache describe-global-replication-groups \
     --global-replication-group-id {{my global datastore }} \
     --show-member-info {{an optional parameter that returns a list of the primary and secondary clusters that make up the global datastore }}
  ```
+ [modify-global-replication-group](https://docs.amazonaws.cn/cli/latest/reference/elasticache/modify-global-replication-group.html)

  ```
  aws elasticache modify-global-replication-group \
     --global-replication-group-id {{my global datastore }} \
     --automatic-failover-enabled \
     --cache-node-type {{node type}} \
     --cache-parameter-group-name {{parameter group name}} \ 
     --engine-version {{engine version}} \
     -—apply-immediately \
     --global-replication-group-description {{description}}
  ```

  **Redis to OSS Valkey cross-engine upgrade for ElastiCache GlobalDataStore**

  You can upgrade an existing Redis OSS global replication group to Valkey using the Console, API or CLI. 

  If you have an existing Redis OSS global replication group you can upgrade to Valkey by specifying the new engine and engine version with modify-global-replication-group API.

  For Linux, OS X, or Unix:

  ```
  aws elasticache modify-global-replication-group \
     --global-replication-group-id myGlobalReplGroup \
     --engine valkey \
     --apply-immediately \
     --engine-version 8.0
  ```

  For Windows:

  ```
  aws elasticache modify-global-replication-group ^
     --global-replication-group-id myGlobalReplGroup ^
     --engine valkey ^
     --apply-immediately ^
     --engine-version 8.0
  ```

  If you have a custom cache parameter group applied to the existing Redis OSS global replication group you wish to upgrade, you will need to pass a custom Valkey cache parameter group in the request as well. The input Valkey custom parameter group must have the same Redis OSS static parameter values as the existing Redis OSS custom parameter group.

  For Linux, OS X, or Unix:

  ```
  aws elasticache modify-global-replication-group \
     --global-replication-group-id myGlobalReplGroup \
     --engine valkey \
     --engine-version 8.0 \
     --apply-immediately \
     --cache-parameter-group-name myParamGroup
  ```

  For Windows:

  ```
  aws elasticache modify-global-replication-group ^
     --global-replication-group-id myGlobalReplGroup ^
     --engine valkey ^
     --engine-version 8.0 ^
     --apply-immediately ^
     --cache-parameter-group-name myParamGroup
  ```
+ [delete-global-replication-group](https://docs.amazonaws.cn/cli/latest/reference/elasticache/delete-global-replication-group.html)

  ```
  aws elasticache delete-global-replication-group \
     --global-replication-group-id {{my global datastore }} \
     --retain-primary-replication-group {{defaults to true }}
  ```
+ [disassociate-global-replication-group](https://docs.amazonaws.cn/cli/latest/reference/elasticache/disassociate-global-replication-group.html)

  ```
  aws elasticache disassociate-global-replication-group \
     --global-replication-group-id {{my global datastore }} \
     --replication-group-id {{my secondary cluster }} \
     --replication-group-region {{the Amazon Region in which the secondary cluster resides}}
  ```
+ [failover-global-replication-group](https://docs.amazonaws.cn/cli/latest/reference/elasticache/failover-global-replication-group.html)

  ```
  aws elasticache failover-replication-group \
     --global-replication-group-id {{my global datastore }}\
     --primary-region {{The Amazon Region of the primary cluster }}\  
     --primary-replication-group-id  {{The name of the global datastore, including the suffix.}}
  ```
+ [increase-node-groups-in-global-replication-group](https://docs.amazonaws.cn/cli/latest/reference/elasticache/increase-node-groups-in-global-replication-group.html)

  ```
  aws elasticache increase-node-groups-in-global-replication-group \
     --apply-immediately {{yes}} \
     --global-replication-group-id {{global-replication-group-name}} \
     --node-group-count {{3}}
  ```
+ [decrease-node-groups-in-global-replication-group](https://docs.amazonaws.cn/cli/latest/reference/elasticache/decrease-node-groups-in-global-replication-group.html)

  ```
  aws elasticache decrease-node-groups-in-global-replication-group \
     --apply-immediately {{yes}} \
     --global-replication-group-id {{global-replication-group-name}} \
     --node-group-count {{3}}
  ```
+ [rebalance-shards-in-global-replication-group](https://docs.amazonaws.cn/cli/latest/reference/elasticache/rebalance-slots-in-global-replication-group.html)

  ```
  aws elasticache rebalance-shards-in-global-replication-group \
     --apply-immediately {{yes}} \
     --global-replication-group-id {{global-replication-group-name}}
  ```

Use help to list all available commands for ElastiCache for Valkey or Redis OSS.

```
aws elasticache help
```

You can also use help to describe a specific command and learn more about its usage: 

```
aws elasticache create-global-replication-group help
```