

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# AWS Database Migration Service を使用して別のデータストアから Amazon Neptune にデータをロードする
<a name="dms-neptune"></a>

AWS Database Migration Service (AWS DMS) は、[サポートされているソースデータベース](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.html)から Neptune にデータを迅速かつ安全にロードできます。移行中でもソースデータベースは完全に利用可能な状態に保たれ、それを利用するアプリケーションのダウンタイムを最小限に抑えられます。

の詳細については、 AWS DMS ユーザーガイドおよび [AWS Database Migration Service API リファレンス](https://docs.aws.amazon.com/dms/latest/APIReference/)を参照してください。 [AWS Database Migration Service](https://docs.aws.amazon.com/dms/latest/userguide/)特に、Neptune クラスターを移行のターゲットとして設定する方法については、[AWS Database Migration Serviceのターゲットとしての Amazon Neptune の使用」](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.Neptune.html)を参照してください。

 AWS DMSを使用して Neptune にデータをインポートするための前提条件は次のとおりです。
+ ソースデータベースからデータを抽出する方法を定義するには、 AWS DMS テーブルマッピングオブジェクトを作成する必要があります (詳細については、 AWS DMS 「 ユーザーガイド[」の「JSON を使用したテーブルマッピングによるテーブルの選択と変換の指定](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.CustomizingTasks.TableMapping.html#CHAP_Tasks.CustomizingTasks.TableMapping.SelectionTransformation)」を参照してください）。このテーブルマッピング設定オブジェクトは、読み取る必要があるテーブル、その順序、および列の命名方法を指定します。また、コピーされる行をフィルタリングし、小文字への変換や四捨五入などの単純な値の変換を提供することもできます。
+ ソースデータベースから抽出されたデータを Neptune にロードする方法を指定するには、Neptune `GraphMappingConfig` を作成する必要があります。RDF データ (SPARQL を使用してクエリされる) の場合、`GraphMappingConfig` は W3 の標準 [R2RML](https://www.w3.org/TR/r2rml/) マッピング言語で記述されます。プロパティグラフデータ (Gremlin を使用してクエリされる) の場合、`GraphMappingConfig` は JSON オブジェクトです ([プロパティグラフ/Gremlin データの GraphMappingConfig レイアウト](dms-neptune-graph-mapping.md#dms-neptune-graph-mapping-gremlin) を参照)。
+  AWS DMS を使用して、Neptune DB クラスターと同じ VPC にレプリケーションインスタンスを作成し、データ転送を仲介する必要があります。
+ また、移行データをステージングするための中間ストレージとして使用する Amazon S3 バケットも必要です。

# Neptune GraphMappingConfig の作成
<a name="dms-neptune-graph-mapping"></a>

作成した `GraphMappingConfig` は、ソースデータストアから抽出されたデータを Neptune DB クラスターにロードする方法を指定します。形式は、目的が RDF データのロードか、プロパティグラフデータのロードかによって異なります。

RDF データの場合、W3 [R2RML](https://www.w3.org/TR/r2rml/) 言語を使用してリレーショナルデータを RDF にマッピングできます。

Gremlin を使用してクエリするプロパティグラフデータをロードする場合、`GraphMappingConfig` の JSON オブジェクトを作成します。

## RDF/SPARQL データの GraphMappingConfig レイアウト
<a name="dms-neptune-graph-mapping-sparql"></a>

SPARQL を使用して照会する RDF データをロードする場合は、[R2RML](https://www.w3.org/TR/r2rml/) に `GraphMappingConfig` を書き込みます。`R2RML` はリレーショナルデータを RDF にマッピングするための標準 W3 言語です。1 つの例を次に示します。

```
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix ex: <http://example.com/ns#> .

<#TriplesMap1>
    rr:logicalTable [ rr:tableName "nodes" ];
    rr:subjectMap [
        rr:template "http://data.example.com/employee/{id}";
        rr:class ex:Employee;
    ];
    rr:predicateObjectMap [
        rr:predicate ex:name;
        rr:objectMap [ rr:column "label" ];
    ] .
```

次に、別の例を示します。

```
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix ex: <http://example.com/#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<#TriplesMap2>
    rr:logicalTable [ rr:tableName "Student" ];
    rr:subjectMap   [ rr:template "http://example.com/{ID}{Name}";
                      rr:class foaf:Person ];
    rr:predicateObjectMap [
        rr:predicate ex:id ;
        rr:objectMap  [ rr:column "ID";
                        rr:datatype xsd:integer ]
    ];
    rr:predicateObjectMap [
        rr:predicate foaf:name ;
        rr:objectMap  [ rr:column "Name" ]
    ] .
```

「[R2RML: RDB to RDF Mapping Language](https://www.w3.org/TR/r2rml/)」にある「W3 Recommendation」には、言語の詳細が記載されています。

## プロパティグラフ/Gremlin データの GraphMappingConfig レイアウト
<a name="dms-neptune-graph-mapping-gremlin"></a>

プロパティグラフデータの同等の `GraphMappingConfig` は、ソースデータから生成される各グラフエンティティのマッピングルールを提供する JSON オブジェクトです。次のテンプレートは、このオブジェクトの各ルールがどのようになるかを示しています。

```
{
  "rules": [
    {
      "rule_id": "(an identifier for this rule)",
      "rule_name": "(a name for this rule)",
      "table_name": "(the name of the table or view being loaded)",
      "vertex_definitions": [
        {
          "vertex_id_template": "{col1}",
          "vertex_label": "(the vertex to create)",
          "vertex_definition_id": "(an identifier for this vertex)",
          "vertex_properties": [
            {
              "property_name": "(name of the property)",
              "property_value_template": "{col2} or text",
              "property_value_type": "(data type of the property)"
            }
          ]
        }
      ]
    },
    {
      "rule_id": "(an identifier for this rule)",
      "rule_name": "(a name for this rule)",
      "table_name": "(the name of the table or view being loaded)",
      "edge_definitions": [
        {
          "from_vertex": {
            "vertex_id_template": "{col1}",
            "vertex_definition_id": "(an identifier for the vertex referenced above)"
          },
          "to_vertex": {
            "vertex_id_template": "{col3}",
            "vertex_definition_id": "(an identifier for the vertex referenced above)"
          },
          "edge_id_template": {
            "label": "(the edge label to add)",
            "template": "{col1}_{col3}"
          },
          "edge_properties":[
            {
              "property_name": "(the property to add)",
              "property_value_template": "{col4} or text",
              "property_value_type": "(data type like String, int, double)"
            }
          ]
        }
      ]
    }
  ]
}
```

頂点ラベルが存在する場合、頂点がここで作成されることを意味しますが、ない場合、頂点が別のソースによって作成されることを意味します。この定義は、頂点プロパティの追加のみです。

従業員レコードのサンプルルールを次に示します。

```
{
  "rules": [
    {
      "rule_id": "1",
      "rule_name": "vertex_mapping_rule_from_nodes",
      "table_name": "nodes",
      "vertex_definitions": [
        {
          "vertex_id_template": "{emp_id}",
          "vertex_label": "employee",
          "vertex_definition_id": "1",
          "vertex_properties": [
            {
              "property_name": "name",
              "property_value_template": "{emp_name}",
              "property_value_type": "String"
            }
          ]
        }
      ]
    },
    {
      "rule_id": "2",
      "rule_name": "edge_mapping_rule_from_emp",
      "table_name": "nodes",
      "edge_definitions": [
        {
          "from_vertex": {
            "vertex_id_template": "{emp_id}",
            "vertex_definition_id": "1"
          },
          "to_vertex": {
            "vertex_id_template": "{mgr_id}",
            "vertex_definition_id": "1"
          },
          "edge_id_template": {
            "label": "reportsTo",
            "template": "{emp_id}_{mgr_id}"
          },
          "edge_properties":[
            {
              "property_name": "team",
              "property_value_template": "{team}",
              "property_value_type": "String"
            }
          ]
        }
      ]
    }
  ]
}
```

# Neptune をターゲットとする AWS DMS レプリケーションタスクの作成
<a name="dms-neptune-replication"></a>

テーブルマッピングおよびグラフマッピング設定を作成したら、次のプロセスを使用してソースストアから Neptune にデータをロードします。問題の APIs の詳細については、 AWS DMS ドキュメントを参照してください。

## AWS DMS レプリケーションインスタンスを作成する
<a name="dms-neptune-replication-instance"></a>

Neptune DB クラスターが実行されている 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 CLI 次のような で AWS DMS [CreateEndpoint](https://docs.aws.amazon.com/dms/latest/APIReference/API_CreateEndpoint.html) API を使用できます。

```
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)
```

## Neptune がステージングデータに使用する Amazon S3 バケットをセットアップする
<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)の説明に従ってバケットを作成します。

バケットに `GetObject`、`PutObject`、`DeleteObject`、および、`ListObject` アクセス許可を付与する IAM ポリシーを作成する必要があります (まだない場合)。

------
#### [ 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 DB クラスターで 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 DB クラスターにアタッチします。これにより、 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 DB クラスターの 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` パラメータで AWS DMS `CreateEndpoint` API に渡される JSON オブジェクトには、次のフィールドがあります。

****
+ **`ServiceAccessRoleArn`**   –   *(必須)* Neptune へのデータの移行をステージングするために使用される S3 バケットへのきめ細かなアクセスを許可する IIAM ロールの ARN。IAM 認可が有効になっている場合、このロールには Neptune DB クラスターにアクセスするアクセス許可も必要です。
+ **`S3BucketName`** – *(必須)*フルロード移行の場合、レプリケーションインスタンスはすべての RDS データを CSV、クワッドファイルに変換し、S3 のこのステージングバケットにアップロードし、それらを Neptune に一括ロードします。
+ **`S3BucketFolder`** – *(必須)* S3 ステージングバケットで使用するフォルダー。
+ **`ErrorRetryDuration`** – *(オプション)* Neptune リクエストが失敗してから再試行リクエストを行うまでに待機するミリ秒数。デフォルトは 250 です。
+ **`MaxRetryCount`**   –   *(オプション)* 再試行可能な失敗後に AWS DMS 行う再試行リクエストの最大数。デフォルトは 5 です。
+ **`MaxFileSize`** – *(オプション)* 移行中に S3 に保存された各ステージングファイルの最大サイズ (バイト単位)。デフォルトは 1,048,576 KB (1 GB) です。
+ **`IsIAMAuthEnabled`** – *(オプション)* IAM 認証が Neptune DB クラスターで有効になっている場合 `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>

前の手順を正常に完了したら、ソースデータストアから Neptune にデータを移行するためのレプリケーションタスクを AWS DMS [CreateReplicationTask](https://docs.aws.amazon.com/dms/latest/APIReference/API_CreateReplicationTask.html.html) API を使用して作成します。

```
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` パラメータは、コピーされたデータを Neptune に保存する方法を指定する [GraphMappingConfig](dms-neptune-graph-mapping.md) を提供します。

## 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
```