

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 建立 Aurora MySQL 的跨區域僅供讀取資料庫叢集。
<a name="AuroraMySQL.Replication.CrossRegion.Creating"></a>

 您可以使用 AWS 管理主控台、AWS Command Line Interface (AWS CLI) 或 Amazon RDS API 來建立屬於跨區域僅供讀取複本的 Aurora 資料庫叢集。您可以透過加密和未加密的資料庫叢集建立跨區域僅供讀取複本。

 使用 AWS 管理主控台 為 Aurora MySQL 建立跨區域僅供讀取複本時，Amazon RDS 會在目標 AWS 區域 中建立資料庫叢集，然後自動建立資料庫執行個體，它是該資料庫叢集的主要執行個體。

 使用 AWS CLI 或 RDS API 建立跨區域僅供讀取複本時，您會先在目標 AWS 區域 中建立資料庫叢集，並等候它成為作用中。一旦它處於作用中狀態，您便可以建立資料庫執行個體，即該資料庫叢集的主要執行個體。

 當僅供讀取複本資料庫叢集的主要執行個體變得可用時，複寫便會開始。

 使用下列程序透過 Aurora MySQL 資料庫叢集建立跨區域僅供讀取複本。這些程序適用透過加密或未加密的資料庫叢集建立僅供讀取複本。

## 主控台
<a name="AuroraMySQL.Replication.CrossRegion.Creating.Console"></a>

**使用 AWS 管理主控台 建立屬於跨區域僅供讀取複本的 Aurora MySQL 資料庫叢集**

1. 登入 AWS 管理主控台，開啟位於 [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/) 的 Amazon RDS 主控台。

1.  在 AWS 管理主控台 的右上角，選取裝載來源資料庫叢集的 AWS 區域。

1.  在導覽窗格中，選擇 **Databases** (資料庫)。

1.  選擇要建立跨區域僅供讀取複本的資料庫叢集。

1. 若為 **Actions (動作)**，請選擇 **Creat cross region replica (建立跨區域僅供讀取複本)**。

1.  在 **Create cross region read replica (建立跨區域僅供讀取複本)** 頁面上，選擇跨區域僅供讀取複本資料庫叢集的選項設定，如下表所述。    
<a name="cross-region-read-replica-settings"></a>[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Replication.CrossRegion.Creating.html)

1.  選擇 **Create (建立)** 來建立您的 Aurora 跨區域僅供讀取複本。

## AWS CLI
<a name="AuroraMySQL.Replication.CrossRegion.Creating.CLI"></a>

**使用 CLI 建立屬於跨區域僅供讀取複本的 Aurora MySQL 資料庫叢集**

1.  在您想要建立僅供讀取複本資料庫叢集的 AWS 區域 中呼叫 AWS CLI [create-db-cluster](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-cluster.html) 命令。包含 `--replication-source-identifier` 選項，並指定要為其建立僅供讀取複本的來源資料庫叢集的 Amazon Resource Name (ARN)。

    對於由 `--replication-source-identifier` 所識別資料庫叢集已加密的跨區域複寫，必須指定 `--kms-key-id` 選項和 `--storage-encrypted` 選項。
**注意**  
 您可以透過指定 `--storage-encrypted` 並提供 `--kms-key-id` 的值，設定從未加密的資料庫叢集對加密的僅供讀取複本的跨區域複寫。

    您無法指定 `--master-username` 和 `--master-user-password` 參數。那些值是從來源資料庫叢集中取得。

    下列程式碼範例會透過 us-west-2 區域中未加密的資料庫叢集快照，在 us-east-1 區域中建立僅供讀取複本。此命令是在 us-east-1 區域中呼叫。此範例會指定 `--manage-master-user-password` 選項來產生主要使用者密碼，並在 Secrets Manager 中管理該密碼。如需更多詳細資訊，請參閱 [使用 Amazon Aurora 和 進行密碼管理 AWS Secrets Manager](rds-secrets-manager.md)。或者，您可以使用 `--master-password` 選項，自行指定和管理密碼。

   對於 Linux、macOS 或 Unix：

   ```
   aws rds create-db-cluster \
     --db-cluster-identifier sample-replica-cluster \
     --engine aurora-mysql \
     --engine-version 8.0.mysql_aurora.3.08.0 \
     --replication-source-identifier arn:aws:rds:us-west-2:123456789012:cluster:sample-master-cluster
   ```

   在 Windows 中：

   ```
   aws rds create-db-cluster ^
     --db-cluster-identifier sample-replica-cluster ^
     --engine aurora-mysql ^
     --engine-version 8.0.mysql_aurora.3.08.0 ^
     --replication-source-identifier arn:aws:rds:us-west-2:123456789012:cluster:sample-master-cluster
   ```

    下列程式碼範例會透過 us-west-2 區域中加密的資料庫叢集快照，在 us-east-1 區域中建立僅供讀取複本。此命令是在 us-east-1 區域中呼叫。

   對於 Linux、macOS 或 Unix：

   ```
   aws rds create-db-cluster \
     --db-cluster-identifier sample-replica-cluster \
     --engine aurora-mysql \
     --engine-version 8.0.mysql_aurora.3.08.0 \
     --replication-source-identifier arn:aws:rds:us-west-2:123456789012:cluster:sample-master-cluster \
     --kms-key-id my-us-east-1-key \
     --storage-encrypted
   ```

   在 Windows 中：

   ```
   aws rds create-db-cluster ^
     --db-cluster-identifier sample-replica-cluster ^
     --engine aurora-mysql ^
     --engine-version 8.0.mysql_aurora.3.08.0 ^
     --replication-source-identifier arn:aws:rds:us-west-2:123456789012:cluster:sample-master-cluster ^
     --kms-key-id my-us-east-1-key ^
     --storage-encrypted
   ```

   AWS GovCloud (美國東部) 和 AWS GovCloud (美國西部) 區域之間的跨區域複寫需要 `--source-region` 選項，其中 `--replication-source-identifier` 識別的資料庫叢集已加密。對於 `--source-region`，請指定來源資料庫叢集的 AWS 區域。

   若未指定 `--source-region`，請指定 `--pre-signed-url` 值。*presigned URL* (預先簽章的 URL) 為包含對來源 AWS 區域 中呼叫 `create-db-cluster` 命令之 Signature 第 4 版簽章請求的 URL。如要進一步了解 `pre-signed-url` 選項，請參閱《*AWS CLI 命令參考*》中的 [ create-db-cluster](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-cluster.html)。

1.  使用 AWS CLI [describe-db-clusters](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-clusters.html) 命令來檢查資料庫叢集是否已可供使用，如下列範例所示。

   ```
   aws rds describe-db-clusters --db-cluster-identifier sample-replica-cluster
   ```

    當 **`describe-db-clusters`** 結果顯示 `available` 的狀態時，請建立資料庫叢集的主要執行個體以便複寫可以開始。若要這麼做，請使用 AWS CLI [create-db-instance](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html) 命令，如下列範例所示。

   對於 Linux、macOS 或 Unix：

   ```
   aws rds create-db-instance \
     --db-cluster-identifier sample-replica-cluster \
     --db-instance-class db.r5.large \
     --db-instance-identifier sample-replica-instance \
     --engine aurora-mysql
   ```

   在 Windows 中：

   ```
   aws rds create-db-instance ^
     --db-cluster-identifier sample-replica-cluster ^
     --db-instance-class db.r5.large ^
     --db-instance-identifier sample-replica-instance ^
     --engine aurora-mysql
   ```

    當資料庫執行個體建立並可用時，複寫即會開始。您可呼叫 AWS CLI [describe-db-instances](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-instances.html) 命令來判斷資料庫執行個體是否可用。

## RDS API
<a name="AuroraMySQL.Replication.CrossRegion.Creating.API"></a>

**使用 API 建立屬於跨區域僅供讀取複本的 Aurora MySQL 資料庫叢集**

1.  在您想要建立僅供讀取複本資料庫叢集的 AWS 區域 中呼叫 RDS API [CreateDBCluster](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBCluster.html) 作業。包含 `ReplicationSourceIdentifier` 參數，並指定要為其建立僅供讀取複本之來源資料庫叢集的 Amazon Resource Name (ARN)。

    對於由 `ReplicationSourceIdentifier` 所識別資料庫叢集已加密的跨區域複寫，須指定 `KmsKeyId` 參數，並將 `StorageEncrypted` 參數設定為 `true`。
**注意**  
 您可以透過將 `StorageEncrypted` 指定為 **true** 並提供 `KmsKeyId` 的值，設定從未加密的資料庫叢集對加密的僅供讀取複本的跨區域複寫。在此情況下，您不需要指定 `PreSignedUrl`。

    您不需要包含 `MasterUsername` 和 `MasterUserPassword` 參數，因為這些值取自來源資料庫叢集。

    下列程式碼範例會透過 us-west-2 區域中未加密的資料庫叢集快照，在 us-east-1 區域中建立僅供讀取複本。此動作是在 us-east-1 區域中呼叫。

   ```
   https://rds.us-east-1.amazonaws.com/
     ?Action=CreateDBCluster
     &ReplicationSourceIdentifier=arn:aws:rds:us-west-2:123456789012:cluster:sample-master-cluster
     &DBClusterIdentifier=sample-replica-cluster
     &Engine=aurora-mysql
     &SignatureMethod=HmacSHA256
     &SignatureVersion=4
     &Version=2014-10-31
     &X-Amz-Algorithm=AWS4-HMAC-SHA256
     &X-Amz-Credential=AKIADQKE4SARGYLE/20161117/us-east-1/rds/aws4_request
     &X-Amz-Date=20160201T001547Z
     &X-Amz-SignedHeaders=content-type;host;user-agent;x-amz-content-sha256;x-amz-date
     &X-Amz-Signature=a04c831a0b54b5e4cd236a90dcb9f5fab7185eb3b72b5ebe9a70a4e95790c8b7
   ```

    下列程式碼範例會透過 us-west-2 區域中加密的資料庫叢集快照，在 us-east-1 區域中建立僅供讀取複本。此動作是在 us-east-1 區域中呼叫。

   ```
   https://rds.us-east-1.amazonaws.com/
     ?Action=CreateDBCluster
     &KmsKeyId=my-us-east-1-key
     &StorageEncrypted=true
     &PreSignedUrl=https%253A%252F%252Frds.us-west-2.amazonaws.com%252F
            %253FAction%253DCreateDBCluster
            %2526DestinationRegion%253Dus-east-1
            %2526KmsKeyId%253Dmy-us-east-1-key
            %2526ReplicationSourceIdentifier%253Darn%25253Aaws%25253Ards%25253Aus-west-2%25253A123456789012%25253Acluster%25253Asample-master-cluster
            %2526SignatureMethod%253DHmacSHA256
            %2526SignatureVersion%253D4
            %2526Version%253D2014-10-31
            %2526X-Amz-Algorithm%253DAWS4-HMAC-SHA256
            %2526X-Amz-Credential%253DAKIADQKE4SARGYLE%252F20161117%252Fus-west-2%252Frds%252Faws4_request
            %2526X-Amz-Date%253D20161117T215409Z
            %2526X-Amz-Expires%253D3600
            %2526X-Amz-SignedHeaders%253Dcontent-type%253Bhost%253Buser-agent%253Bx-amz-content-sha256%253Bx-amz-date
            %2526X-Amz-Signature%253D255a0f17b4e717d3b67fad163c3ec26573b882c03a65523522cf890a67fca613
     &ReplicationSourceIdentifier=arn:aws:rds:us-west-2:123456789012:cluster:sample-master-cluster
     &DBClusterIdentifier=sample-replica-cluster
     &Engine=aurora-mysql
     &SignatureMethod=HmacSHA256
     &SignatureVersion=4
     &Version=2014-10-31
     &X-Amz-Algorithm=AWS4-HMAC-SHA256
     &X-Amz-Credential=AKIADQKE4SARGYLE/20161117/us-east-1/rds/aws4_request
     &X-Amz-Date=20160201T001547Z
     &X-Amz-SignedHeaders=content-type;host;user-agent;x-amz-content-sha256;x-amz-date
     &X-Amz-Signature=a04c831a0b54b5e4cd236a90dcb9f5fab7185eb3b72b5ebe9a70a4e95790c8b7
   ```

   對於 AWS GovCloud (美國東部) 和 AWS GovCloud (美國西部) 區域之間的跨區域複寫，其中 `ReplicationSourceIdentifier` 識別的資料庫叢集已加密，亦請指定 `PreSignedUrl` 參數。預先簽章的 URL 必須是對 `CreateDBCluster` API 作業的有效請求，而此動作可執行於包含要複寫之加密資料庫叢集的來源 AWS 區域 中。KMS 金鑰識別碼用來加密僅供讀取複本，而且必須是對目的地 AWS 區域 有效的 KMS 金鑰。如要自動而非手動產生預先簽章的 URL，請改為使用 AWS CLI [create-db-cluster](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-cluster.html) 命令搭配 `--source-region` 選項。

1.  使用 RDS API [DescribeDBClusters](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeDBClusters.html) 作業來檢查資料庫叢集是否已可供使用，如下列範例所示。

   ```
   https://rds.us-east-1.amazonaws.com/
     ?Action=DescribeDBClusters
     &DBClusterIdentifier=sample-replica-cluster
     &SignatureMethod=HmacSHA256
     &SignatureVersion=4
     &Version=2014-10-31
     &X-Amz-Algorithm=AWS4-HMAC-SHA256
     &X-Amz-Credential=AKIADQKE4SARGYLE/20161117/us-east-1/rds/aws4_request
     &X-Amz-Date=20160201T002223Z
     &X-Amz-SignedHeaders=content-type;host;user-agent;x-amz-content-sha256;x-amz-date
     &X-Amz-Signature=84c2e4f8fba7c577ac5d820711e34c6e45ffcd35be8a6b7c50f329a74f35f426
   ```

    當 `DescribeDBClusters` 結果顯示 `available` 的狀態時，請建立資料庫叢集的主要執行個體，則複寫可隨即開始。若要這麼做，請使用 RDS API [CreateDBInstance](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html) 動作，如下列範例所示。

   ```
   https://rds.us-east-1.amazonaws.com/
     ?Action=CreateDBInstance
     &DBClusterIdentifier=sample-replica-cluster
     &DBInstanceClass=db.r5.large
     &DBInstanceIdentifier=sample-replica-instance
     &Engine=aurora-mysql
     &SignatureMethod=HmacSHA256
     &SignatureVersion=4
     &Version=2014-10-31
     &X-Amz-Algorithm=AWS4-HMAC-SHA256
     &X-Amz-Credential=AKIADQKE4SARGYLE/20161117/us-east-1/rds/aws4_request
     &X-Amz-Date=20160201T003808Z
     &X-Amz-SignedHeaders=content-type;host;user-agent;x-amz-content-sha256;x-amz-date
     &X-Amz-Signature=125fe575959f5bbcebd53f2365f907179757a08b5d7a16a378dfa59387f58cdb
   ```

    當資料庫執行個體建立並可用時，複寫即會開始。您可呼叫 AWS CLI [DescribeDBInstances](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeDBInstances.html) 命令來判斷資料庫執行個體是否可用。

## 檢視 Amazon Aurora MySQL 跨區域複本
<a name="AuroraMySQL.Replication.CrossRegion.Viewing"></a>

 您可呼叫 [describe-db-clusters](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-clusters.html) AWS CLI 命令或 [DescribeDBClusters](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeDBClusters.html) RDS API 作業來檢視您 Amazon Aurora MySQL 資料庫叢集的跨區域複寫關係。於回應中，請參閱 `ReadReplicaIdentifiers` 欄位，以取得任何跨區域讀取複本資料庫叢集的資料庫叢集識別符。有關作為複寫來源之來源資料庫叢集的 ARN，請參閱 `ReplicationSourceIdentifier` 元素。