

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 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 사용 설명서](https://docs.aws.amazon.com/dms/latest/userguide/) 및 [AWS Database Migration Service API 참조](https://docs.aws.amazon.com/dms/latest/APIReference/)에서 확인할 수 있습니다. 특히 [Amazon Neptune을 AWS Database Migration Service의 대상으로 사용](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.Neptune.html)에서 Neptune 클러스터를 마이그레이션 대상으로 설정하는 방법을 확인할 수 있습니다.

다음은 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`는 [Property-Graph/Gremlin 데이터용 GraphMappingConfig 레이아웃](dms-neptune-graph-mapping.md#dms-neptune-graph-mapping-gremlin)에 설명된 JSON 객체입니다.
+ 데이터 전송 AWS DMS 을 조정하려면를 사용하여 Neptune DB 클러스터와 동일한 VPC에 복제 인스턴스를 생성해야 합니다.
+ 또한 마이그레이션 데이터를 스테이징하기 위한 중간 스토리지로 사용할 Amazon S3 버킷이 필요합니다.

# Neptune GraphMappingConfig 생성
<a name="dms-neptune-graph-mapping"></a>

생성한 `GraphMappingConfig`는 소스 데이터 스토어에서 추출한 데이터를 Neptune DB 클러스터에 로드하는 방법을 지정합니다. 형식은 RDF 데이터를 로드하는 데 사용할지 속성 그래프 데이터를 로드하는 데 사용할지 여부에 따라 다릅니다.

RDF 데이터의 경우 RDF에 관계형 데이터를 매핑하기 위해 W3 [R2RML](https://www.w3.org/TR/r2rml/) 언어를 사용할 수 있습니다.

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 언어입니다. 다음은 한 가지 예입니다.

```
@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은 언어의 세부 정보를 제공합니다.

## Property-Graph/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에 로드합니다. 해당 API에 대한 자세한 내용은 AWS DMS 설명서를 참조하세요. APIs 

## 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 게이트웨이 엔드포인트를 생성합니다. [게이트웨이 엔드포인트 생성](https://docs.aws.amazon.com/vpc/latest/userguide/vpce-gateway.html#create-gateway-endpoint)에 설명된 대로 AWS Management Console 또는를 사용하여이 AWS CLI 작업을 수행할 수 있습니다.

## 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` 파라미터에서 API로 AWS DMS `CreateEndpoint` 전달되는 JSON 객체에는 다음 필드가 있습니다.

****
+ **`ServiceAccessRoleArn`**   –   *(필수)* Neptune으로의 데이터 마이그레이션을 준비하는 데 사용되는 S3 버킷에 대한 세분화된 액세스를 허용하는 IAM 역할의 ARN입니다. IAM 권한 부여가 활성화된 경우 이 역할에 Neptune DB 클러스터에 액세스할 수 있는 권한도 있어야 합니다.
+ **`S3BucketName`**   –   *(필수)* 전체 로드 마이그레이션의 경우 복제 인스턴스는 모든 RDS 데이터를 CSV로 변환하고, 쿼드 파일을 S3의 이 스테이징 버킷으로 업로드한 다음, Neptune에 대량 로드합니다.
+ **`S3BucketFolder`**   –   *(필수)* S3 스테이징 버킷에서 사용할 폴더입니다.
+ **`ErrorRetryDuration`**   –   *(선택 사항)* Neptune 요청이 실패한 후 요청을 재시도하기 전에 대기할 시간(밀리초)입니다. 기본값은 250입니다.
+ **`MaxRetryCount`**   –   *(선택 사항)* 재시도 가능 실패 후 AWS DMS 수행해야 하는 최대 재시도 요청 수입니다. 기본값은 5입니다.
+ **`MaxFileSize`**   –   *(선택 사항)* 마이그레이션 중에 S3에 저장된 각 스테이징 파일의 최대 크기(바이트)입니다. 기본값은 1,048,576KB(1GB)입니다.
+ **`IsIAMAuthEnabled`**   –   *(선택 사항)* Neptune DB 클러스터에서 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` 파라미터는 복사할 데이터를 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
```