

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

# を使用して DB クラスターで Neptune ML を AWS CLI セットアップする
<a name="machine-learning-cluster-setup"></a>

 CloudFormation クイックスタートテンプレートと に加えて AWS マネジメントコンソール、 を使用して Neptune ML を設定することもできます AWS CLI。

## 新しい Neptune ML クラスター用の DB クラスターパラメータグループを作成します。
<a name="machine-learning-enabling-create-param-group"></a>

次の AWS CLI コマンドは、新しい DB クラスターパラメータグループを作成し、Neptune ML で動作するように設定します。

**Neptune ML 用の DB クラスターパラメータグループを作成して設定するには**

1. 新しい DB クラスターのパラメータグループを作成します。

   ```
   aws neptune create-db-cluster-parameter-group \
     --db-cluster-parameter-group-name (name of the new DB cluster parameter group) \
     --db-parameter-group-family neptune1
     --description "(description of your machine learning project)" \
     --region (AWS region, such as us-east-1)
   ```

1. SageMaker AI を呼び出してジョブを作成し、ホストされた ML モデルから予測を取得するときに使用する、DB クラスターの `SageMakerExcecutionIAMRole` の ARN に設定された `neptune_ml_iam_role` DB クラスターパラメータを作成します。

   ```
   aws neptune modify-db-cluster-parameter-group \
     --db-cluster-parameter-group-name (name of the new DB cluster parameter group) \
     --parameters "ParameterName=neptune_ml_iam_role, \
                   ParameterValue=ARN of the SageMakerExcecutionIAMRole, \
                   Description=NeptuneMLRole, \
                   ApplyMethod=pending-reboot" \
     --region (AWS region, such as us-east-1)
   ```

   このパラメータを設定すると、Neptune はコールごとにロールを渡す必要なく SageMaker AI にアクセスできます。

   `SageMakerExcecutionIAMRole` を作成する方法については、[カスタム NeptuneSageMakerIAMRole ロールを作成する](machine-learning-manual-setup.md#ml-manual-setup-sm-role) を参照してください。

1. 最後に、新しい DB クラスターパラメーターグループのすべてのパラメータが希望通りに設定されていることを確認するには、`describe-db-cluster-parameters` を実行します。

   ```
   aws neptune describe-db-cluster-parameters \
     --db-cluster-parameter-group-name (name of the new DB cluster parameter group) \
     --region (AWS region, such as us-east-1)
   ```

## Neptune ML で使用する DB クラスターに新しい DB クラスターパラメータグループをアタッチします。
<a name="machine-learning-enabling-attach-param-group"></a>

これで、次のコマンドを使用して、作成した新しい DB クラスターパラメータグループを既存の DB クラスターにアタッチできます。

```
aws neptune modify-db-cluster \
  --db-cluster-identifier (the name of your existing DB cluster) \
  --apply-immediately
  --db-cluster-parameter-group-name (name of your new DB cluster parameter group) \
  --region (AWS region, such as us-east-1)
```

すべてのパラメータを有効にするために、DB クラスターを再起動します。

```
aws neptune reboot-db-instance
  --db-instance-identifier (name of the primary instance of your DB cluster) \
  --profile (name of your AWS profile to use) \
  --region (AWS region, such as us-east-1)
```

または、Neptune ML で使用する新しい DB クラスターを作成する場合は、次のコマンドを使用して新しいパラメータグループがアタッチされたクラスターを作成し、新しいプライマリ (ライター) インスタンスを作成できます。

```
cluster-name=(the name of the new DB cluster)
aws neptune create-db-cluster
  --db-cluster-identifier ${cluster-name}
  --engine graphdb \
  --engine-version 1.0.4.1 \
  --db-cluster-parameter-group-name (name of your new DB cluster parameter group) \
  --db-subnet-group-name (name of the subnet to use) \
  --region (AWS region, such as us-east-1)

aws neptune create-db-instance
  --db-cluster-identifier ${cluster-name}
  --db-instance-identifier ${cluster-name}-i \
  --db-instance-class (the instance class to use, such as db.r5.xlarge)
  --engine graphdb \
  --region (AWS region, such as us-east-1)
```

## SageMaker AI および Amazon S3 リソースにアクセスできるように DB クラスターに `NeptuneSageMakerIAMRole` をアタッチする
<a name="machine-learning-enabling-attach-neptune-sagemaker-role"></a>

最後に、[カスタム NeptuneSageMakerIAMRole ロールを作成する](machine-learning-manual-setup.md#ml-manual-setup-sm-role) に記載されている手順に従って、DB クラスターが SageMaker AI および Amazon S3 と通信できるようにする IAM ロールを作成します。次に、以下のコマンドを使用して、作成した `NeptuneSageMakerIAMRole` ロールを DB クラスターにアタッチします。

```
aws neptune add-role-to-db-cluster
  --db-cluster-identifier ${cluster-name}
  --role-arn arn:aws:iam::(the ARN number of the role's ARN):role/NeptuneMLRole \
  --region (AWS region, such as us-east-1)
```

## Neptune VPC で SageMaker AI の 2 つのエンドポイントを作成します。
<a name="machine-learning-sm-endpoints"></a>

Neptune ML は、Neptune DB クラスターの VPC に 2 つの SageMaker AI エンドポイントを必要とします。
+ `com.amazonaws.(AWS region, like us-east-1).sagemaker.runtime`
+ `com.amazonaws.(AWS region, like us-east-1).sagemaker.api`

クイックスタート CloudFormation テンプレートを使用していない場合は、これらを自動的に作成します。次の AWS CLI コマンドを使用して作成できます。

これは、`sagemaker.runtime` エンドポイントを作成します。

```
aws ec2 create-vpc-endpoint
  --vpc-id (the ID of your Neptune DB cluster's VPC)
  --vpc-endpoint-type Interface
  --service-name com.amazonaws.(AWS region, like us-east-1).sagemaker.runtime
  --subnet-ids (the subnet ID or IDs that you want to use)
  --security-group-ids (the security group for the endpoint network interface, or omit to use the default)
  --private-dns-enabled
```

そしてこれは、`sagemaker.api` エンドポイントを作成します。

```
aws ec2 create-vpc-endpoint
  --vpc-id (the ID of your Neptune DB cluster's VPC)
  --vpc-endpoint-type Interface
  --service-name com.amazonaws.(AWS region, like us-east-1).sagemaker.api
  --subnet-ids (the subnet ID or IDs that you want to use)
  --security-group-ids (the security group for the endpoint network interface, or omit to use the default)
  --private-dns-enabled
```

また、[VPC コンソール](https://console.aws.amazon.com/vpc/) を使用して、これらのエンドポイントを作成することもできます。「[Secure prediction calls in Amazon SageMaker with AWS PrivateLink](https://aws.amazon.com/blogs/machine-learning/secure-prediction-calls-in-amazon-sagemaker-with-aws-privatelink/)」および[「Securing all Amazon SageMaker API calls with AWS PrivateLink](https://aws.amazon.com/blogs/machine-learning/securing-all-amazon-sagemaker-api-calls-with-aws-privatelink/)」を参照してください。

## DB クラスターパラメータグループに SageMaker AI 推論エンドポイントパラメータを作成します。
<a name="machine-learning-set-inference-endpoint-cluster-parameter"></a>

すべてのクエリで使用しているモデルの SageMaker AI 推論エンドポイントを指定する必要がないようにするには、Neptune ML の DB クラスターパラメータグループで `neptune_ml_endpoint` という名前の DB クラスターパラメータを作成します。パラメータを、対象のインスタンスエンドポイントの `id` に設定します。

これを行うには、次の AWS CLI コマンドを使用します。

```
aws neptune modify-db-cluster-parameter-group \
  --db-cluster-parameter-group-name neptune-ml-demo \
  --parameters "ParameterName=neptune_ml_endpoint, \
                ParameterValue=(the name of the SageMaker AI inference endpoint you want to query), \
                Description=NeptuneMLEndpoint, \
                ApplyMethod=pending-reboot" \
  --region (AWS region, such as us-east-1)
```