Amazon Neptune默认情况下不支持匿名身份验证。但是,您可以使用IAM身份验证和VPC端点来为数据集启用安全性。
下面是一个使用IAM身份验证和VPC端点来连接到Amazon Neptune的Python示例:
import boto3
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.structure.graph import Graph
# Set up the IAM credentials
session = boto3.Session(region_name='us-west-2')
credentials = session.get_credentials().get_frozen_credentials()
# Get the VPC endpoint URL from the AWS Console
endpoint_url = "wss://my-neptune-cluster.us-west-2.neptune.amazonaws.com:8182/gremlin"
# Create the Gremlin connection with IAM authentication and a VPC endpoint
graph = Graph()
connection = DriverRemoteConnection(
endpoint_url, 'g',
username=credentials.access_key,
password=credentials.secret_key,
translator='TraversalSourceTranslatorV2',
ssl=True)
g = graph.traversal().withRemote(connection)
# Example Gremlin query
response = g.V().limit(10).toList()
print(response)
您需要确保已正确配置IAM身份验证和VPC端点,以确保数据的安全性和保护。