本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用Amazon CLI在数据库集群上设置 Neptune ML
除了Amazon CloudFormation快速入门模板和Amazon Web Services Management Console,您还 Neptune 使用Amazon CLI.
1. 为新的 Neptune ML 集群创建数据库集群参数组
以下Amazon CLI命令创建一个新的数据库集群参数组,然后将其设置为与 Neptune ML 配合使用:
为 Neptune ML 创建和配置数据库集群参数组
-
创建新的数据库集群参数组:
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)
-
创建
neptune_ml_iam_role
数据库集群参数设置为的 ARNSageMakerExcecutionIAMRole
让您的数据库集群在调用 SageMaker 创建作业和从托管机器学习模型中获取预测时使用: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角色. -
最后,使用
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角色创建允许数据库集群与 SageMaker 和 Amazon S3 进行通信的 IAM 角色。然后,使用以下命令将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.runtimecom.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 控制台
在数据库集群参数组中创建 SageMaker 推理终端节点参数组
为避免必须指定模型的 SageMaker 推理终端节点,请创建一个名为的数据库集群参数,请创建一个名为neptune_ml_endpoint
在 Neptune ML 的数据库集群参数组中。将参数设置为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)