使用 Amazon CLI 在数据库集群上设置 Neptune ML - Amazon Neptune
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Amazon CLI 在数据库集群上设置 Neptune ML

除了 Amazon CloudFormation 快速入门模板和 Amazon Web Services Management Console之外,还可以使用 Amazon CLI 设置 Neptune ML。

1. 为 Neptune ML 集群创建数据库集群参数组

以下 Amazon CLI 命令创建新的数据库集群参数组并将其设置为与 Neptune ML 结合使用:

为 Neptune ML 创建和配置数据库集群参数组
  1. 创建新的数据库集群参数组:

    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 (Amazon region, such as us-east-1)
  2. 创建一个设置为 SageMakerExcecutionIAMRole 的 ARN 的 neptune_ml_iam_role 数据库集群参数,供您的数据库集群在调用 SageMaker 以创建任务和从托管 ML 模型获取预测时使用:

    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 (Amazon region, such as us-east-1)

    设置此参数允许 Neptune 访问 SageMaker,而无需在每次调用时都传递角色。

    有关如何创建 SageMakerExcecutionIAMRole 的信息,请参阅创建自定义 NeptuneSageMakerIAMRole 角色

  3. 最后,使用 describe-db-cluster-parameters 检查新数据库集群参数组中的所有参数是否都设置为您希望的值:

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

将新的数据库集群参数组附加到将与 Neptune ML 一起使用的数据库集群

现在,您可以使用以下命令,将刚刚创建的新数据库集群参数组附加到现有数据库集群:

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 (Amazon region, such as us-east-1)

要使所有参数生效,您可以重启数据库集群:

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

或者,如果您要创建与 Neptune ML 结合使用的新数据库集群,则可以使用以下命令创建附加了新参数组的集群,然后创建新的主(写入器)实例:

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 (Amazon 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 (Amazon region, such as us-east-1)

NeptuneSageMakerIAMRole 连接到您的数据库集群,以便它可以访问 SageMaker 和 Amazon S3 资源

最后,按照创建自定义 NeptuneSageMakerIAMRole 角色中的说明创建一个 IAM 角色,该角色将允许您的数据库集群与 SageMaker 和 Amazon S3 通信。然后,使用以下命令将您创建的 NeptuneSageMakerIAMRole 角色附加到数据库集群:

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 (Amazon region, such as us-east-1)

在 Neptune VPC 中为 SageMaker 创建两个端点

Neptune ML 需要在 Neptune 数据库集群的 VPC 中使用两个 SageMaker 端点:

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

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

如果您尚未使用快速入门 Amazon CloudFormation 模板(它会自动为您创建这些端点),则可以使用以下 Amazon CLI 命令来创建它们:

此命令创建 sagemaker.runtime 端点:

create-vpc-endpoint --vpc-id (the ID of your Neptune DB cluster's VPC) --service-name com.amazonaws.(Amazon 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 create-vpc-endpoint --vpc-id (the ID of your Neptune DB cluster's VPC) --service-name com.amazonaws.(Amazon 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 控制台创建这些端点。请参阅使用 Amazon PrivateLink 在 Amazon SageMaker 中保护预测调用使用 Amazon PrivateLink 保护所有 Amazon SageMaker API 调用

在数据库集群参数组中创建 SageMaker 推理端点参数

为了避免在对您正在使用的模型的 SageMaker 推理端点进行的每次查询中都必须指定该端点,请在 Neptune ML 的数据库集群参数组中创建一个名为 neptune_ml_endpoint 的数据库集群参数。将此参数设置为相关实例端点的 id

您可以使用以下 Amazon 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 inference endpoint you want to query), \ Description=NeptuneMLEndpoint, \ ApplyMethod=pending-reboot" \ --region (Amazon region, such as us-east-1)