

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

# 建立以 Neptune 做為目標的 AWS DMS 複寫任務
<a name="dms-neptune-replication"></a>

一旦建立了資料表映射和圖形映射組態，就會使用下列程序，將資料從來源存放區載入至 Neptune。如需相關 APIs的詳細資訊，請參閱 AWS DMS 文件。

## 建立 AWS DMS 複寫執行個體
<a name="dms-neptune-replication-instance"></a>

在執行 Neptune 資料庫叢集的 VPC 中建立 AWS DMS 複寫執行個體 （請參閱 AWS DMS 《 使用者指南》中的[使用 AWS DMS 複寫執行個體](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_ReplicationInstance.html)和 [CreateReplicationInstance](https://docs.aws.amazon.com/dms/latest/APIReference/API_CreateReplicationInstance.html))。您可以使用如下所示的 AWS CLI 命令來執行此操作：

```
aws dms create-replication-instance \
    --replication-instance-identifier {{(the replication instance identifier)}} \
    --replication-instance-class {{(the size and capacity of the instance, like 'dms.t2.medium')}} \
    --allocated-storage {{(the number of gigabytes to allocate for the instance initially)}} \
    --engine-version {{(the DMS engine version that the instance should use)}} \
    --vpc-security-group-ids {{(the security group to be used with the instance)}}
```

## 建立來源資料庫的 AWS DMS 端點
<a name="dms-neptune-source-endpoint"></a>

下一個步驟是為您的來源資料存放區建立 AWS DMS 端點。您可以在 中使用 AWS DMS [CreateEndpoint](https://docs.aws.amazon.com/dms/latest/APIReference/API_CreateEndpoint.html) API， AWS CLI 如下所示：

```
aws dms create-endpoint \
    --endpoint-identifier {{(source endpoint identifier)}} \
    --endpoint-type source \
    --engine-name {{(name of source database engine)}} \
    --username {{(user name for database login)}} \
    --password {{(password for login)}} \
    --server-name {{(name of the server)}} \
    --port {{(port number)}} \
    --database-name {{(database name)}}
```

## 設定 Amazon S3 儲存貯體供 Neptune 用於預備資料
<a name="dms-neptune-s3-staging-bucket"></a>

如果您沒有可用於暫存資料的 Amazon S3 儲存貯體，請按照《 Amazon S3 入門指南》中的[建立儲存貯體](https://docs.aws.amazon.com/AmazonS3/latest/userguide/CreatingABucket.html)，或《主控台使用者指南》中的[如何建立 S3 儲存貯體？](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket.html)所述建立儲存貯體。

如果您還沒有 IAM 政策，您必須建立一個 IAM 政策，將 `GetObject`、`PutObject`、`DeleteObject` 和 `ListObject` 許可授與儲存貯體：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "ListObjectsInBucket",
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket"
      ],
      "Resource": [
        "arn:aws:s3:::{{amzn-s3-demo-bucket}}"
      ]
    },
    {
      "Sid": "AllObjectActions",
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:PutObject",
        "s3:DeleteObject"
      ],
      "Resource": [
        "arn:aws:s3:::{{amzn-s3-demo-bucket}}/*"
      ]
    }
  ]
}
```

------

如果您的 Neptune 資料庫叢集已啟用 IAM 身分驗證，您還必須包含下列政策：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "VisualEditor0",
      "Effect": "Allow",
      "Action": "neptune-db:*",
      "Resource": "arn:aws:neptune-db:{{us-east-1}}:{{111122223333}}:{{cluster-resource-id}}/*"
    }
  ]
}
```

------

建立 IAM 角色做為要附加政策的信任文件：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Service": "dms.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    },
    {
      "Sid": "neptune",
      "Effect": "Allow",
      "Principal": {
        "Service": "rds.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
```

------

在將政策附加到角色之後，將此角色附加到您的 Neptune 資料庫叢集。這將允許 AWS DMS 使用 儲存貯體來暫存要載入的資料。

## 在 Neptune VPC 中建立 Amazon S3 端點
<a name="dms-neptune-s3-endpoint"></a>

現在，在 Neptune 叢集所在的 VPC 中為您的中繼 Amazon S3 儲存貯體建立一個 VPC 閘道端點。您可以使用 AWS 管理主控台 或 AWS CLI 來執行此操作，如[建立閘道端點](https://docs.aws.amazon.com/vpc/latest/userguide/vpce-gateway.html#create-gateway-endpoint)中所述。

## 建立 Neptune AWS DMS 的目標端點
<a name="dms-neptune-target-endpoint"></a>

為您的目標 Neptune 資料庫叢集建立 AWS DMS 端點。您可以使用 AWS DMS [CreateEndpoint](https://docs.aws.amazon.com/dms/latest/APIReference/API_CreateEndpoint.html) API 搭配 參數，`NeptuneSettings`如下所示：

```
aws dms create-endpoint \
    --endpoint-identifier {{(target endpoint identifier)}} \
    --endpoint-type target \
    --engine-name neptune \
    --server-name {{(name of the server)}} \
    --port {{(port number)}} \
    --neptune-settings '{ \
      "ServiceAccessRoleArn": "{{(ARN of the service access role)}}", \
      "S3BucketName": "{{(name of S3 bucket to use for staging files when migrating)}}", \
      "S3BucketFolder": "{{(name of the folder to use in that S3 bucket)}}", \
      "ErrorRetryDuration": {{(number of milliseconds to wait between bulk-load retries)}}, \
      "MaxRetryCount": {{(the maximum number of times to retry a failing bulk-load job)}}, \
      "MaxFileSize": {{(maximum file size, in bytes, of the staging files written to S3)}}, \
      "IamAuthEnabled": {{(set to true if IAM authentication is enabled on the Neptune cluster)}} }'
```

傳遞至其`NeptuneSettings`參數中 API 的 AWS DMS `CreateEndpoint` JSON 物件具有下列欄位：

****
+ **`ServiceAccessRoleArn`** – *(必要)* IAM 角色的 ARN，此角色允許精細存取 S3 儲存貯體，此儲存貯體用來暫存遷移至 Neptune 的資料。此角色也應具有存取 Neptune 資料庫叢集的許可 (如果該叢集已啟用 IAM 授權)。
+ **`S3BucketName`** – *(必要)* 若是完整載入遷移，複寫執行個體會將所有 RDS 資料轉換為 CSV、四元組檔案，並將它們上傳到 S3 中的這個暫存儲存貯體，然後再大量載入至 Neptune。
+ **`S3BucketFolder`** – *(必要)* 要在 S3 暫存儲存貯體中使用的資料夾。
+ **`ErrorRetryDuration`** – *(選用)* Neptune 請求失敗後，再次提出重試請求之前要等待的毫秒數。預設值為 250。
+ **`MaxRetryCount`**   – *（選用）* 在可重試失敗之後 AWS DMS ，應提出的重試請求數目上限。預設值為 5。
+ **`MaxFileSize`** – *(選用)* 遷移期間儲存至 S3 的每個暫存檔案的大小上限 (以位元組為單位)。預設值為 1,048,576 KB (1 GB)。
+ **`IsIAMAuthEnabled`** – *選用)* 如果已在 Neptune 資料庫叢集上啟用 IAM 驗證，則設為 `true`，否則設為 `false`。預設值為 `false`。

## 測試新端點的連線
<a name="dms-neptune-test-endpoints"></a>

您可以使用 AWS DMS [TestConnection](https://docs.aws.amazon.com/dms/latest/APIReference/API_TestConnection.html) API 來測試每個新端點的連線，如下所示：

```
aws dms test-connection \
    --replication-instance-arn {{(the ARN of the replication instance)}} \
    --endpoint-arn {{(the ARN of the endpoint you are testing)}}
```

## 建立 AWS DMS 複寫任務
<a name="dms-neptune-replication-task"></a>

一旦成功完成了先前的步驟，請使用如下的 AWS DMS [CreateReplicationTask](https://docs.aws.amazon.com/dms/latest/APIReference/API_CreateReplicationTask.html.html) API 建立複寫工作，將資料從來源資料存放區遷移至 Neptune：

```
aws dms create-replication-task \
    --replication-task-identifier {{(name for the replication task)}} \
    --source-endpoint-arn {{(ARN of the source endpoint)}} \
    --target-endpoint-arn {{(ARN of the target endpoint)}} \
    --replication-instance-arn {{(ARN of the replication instance)}} \
    --migration-type full-load \
    --table-mappings {{(table-mapping JSON object or URI like 'file:///tmp/table-mappings,json')}} \
    --task-data {{(a GraphMappingConfig object or URI like 'file:///tmp/graph-mapping-config.json')}}
```

`TaskData` 參數提供 [GraphMappingConfig](dms-neptune-graph-mapping.md)，其會指定所複製資料應該如何儲存在 Neptune 中。

## 啟動 AWS DMS 複寫任務
<a name="dms-neptune-start-task"></a>

現在您可以啟動複寫任務：

```
aws dms start-replication-task
    --replication-task-arn {{(ARN of the replication task started in the previous step)}}
    --start-replication-task-type start-replication
```