を使用して DB クラスターに Neptune ML を AWS CLI セットアップする - Amazon Neptune

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

を使用して DB クラスターに Neptune ML を AWS CLI セットアップする

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

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

次の 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)
  2. ジョブを作成し、ホストされた ML モデルから予測を取得するために SageMaker AI を呼び出すときに使用する DB クラスターSageMakerExcecutionIAMRoleneptune_ml_iam_roleパラメータを ARNの に設定します。

    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 ロールを作成する を参照してください。

  3. 最後に、新しい 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 クラスターパラメータグループをアタッチします。

これで、次のコマンドを使用して、作成した新しい 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)

を DB クラスターNeptuneSageMakerIAMRoleにアタッチして、 SageMaker AI および Amazon S3 リソースにアクセスできるようにします。

最後に、カスタム NeptuneSageMakerIAMRole ロールを作成する「」の手順に従って、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 で SageMaker AI 用の 2 つのエンドポイントを作成する VPC

Neptune ML には、Neptune DB クラスターの に 2 つの SageMaker AI エンドポイントが必要ですVPC。

  • com.amazonaws.(AWS region, like us-east-1).sagemaker.runtime

  • com.amazonaws.(AWS region, like us-east-1).sagemaker.api

クイックスタート AWS 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 コンソールを使用してこれらのエンドポイントを作成することもできます。「Secure prediction calls in Amazon SageMaker with AWS PrivateLink and Securing all Amazon SageMaker API calls with AWS PrivateLink」を参照してください。

DB クラスターパラメータグループに SageMaker AI 推論エンドポイントパラメータを作成する

Neptune ML の DB クラスターパラメータグループneptune_ml_endpointで という名前の DB クラスターパラメータを作成して、クエリを実行するたびに使用しているモデルの SageMaker AI 推論エンドポイントを指定しないようにします。パラメータを、対象のインスタンスエンドポイントの 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)