View a markdown version of this page

使用命令行工具访问亚马逊 Neptune - Amazon Neptune
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

使用命令行工具访问亚马逊 Neptune

您可以使用和等 Amazon curl软件开发工具包和 HTTP 工具向 Nep awscurl tune 数据库集群提交查询。 Amazon CLI以下部分介绍如何设置每个工具以及如何运行基本的 Gremlin 和 OpenCypher 查询。

使用 Amazon CLI

这些aws neptunedata命令允许您运行 Gremlin 和 OpenCypher 查询、检查引擎状态、管理批量加载等。有关完整的命令参考,请参阅neptunedata《 Amazon CLI 命令参考》。

以下示例显示如何运行基本查询:

Gremlin
aws neptunedata execute-gremlin-query \ --endpoint-url https://your-neptune-endpoint:port \ --region us-east-1 \ --gremlin-query "g.V().limit(1)"

有关更多信息,请参阅《命令参考》中的 execute-gremlin-query 。 Amazon CLI

openCypher
aws neptunedata execute-open-cypher-query \ --endpoint-url https://your-neptune-endpoint:port \ --region us-east-1 \ --open-cypher-query "MATCH (n) RETURN n LIMIT 1"

有关更多信息,请参阅《命令参考》中的 execute-open-cypher-query 。 Amazon CLI

使用 Amazon SDK

您可以通过 Amazon 软件开发工具包使用海王星数据 API 以编程方式运行查询。以下 Python 示例显示了如何运行基本查询:

Gremlin
import boto3 import json from botocore.config import Config # Disable the client-side read timeout and retries so that # Neptune's server-side neptune_query_timeout controls query duration. client = boto3.client( 'neptunedata', endpoint_url='https://your-neptune-endpoint:port', config=Config(read_timeout=None, retries={'total_max_attempts': 1}) ) response = client.execute_gremlin_query( gremlinQuery='g.V().limit(1)', serializer='application/vnd.gremlin-v3.0+json;types=false' ) print(json.dumps(response['result'], indent=2))

有关其他语言的 Amazon SDK 示例,请参阅Amazon SDK

openCypher
import boto3 import json from botocore.config import Config # Disable the client-side read timeout and retries so that # Neptune's server-side neptune_query_timeout controls query duration. client = boto3.client( 'neptunedata', endpoint_url='https://your-neptune-endpoint:port', config=Config(read_timeout=None, retries={'total_max_attempts': 1}) ) response = client.execute_open_cypher_query( openCypherQuery='MATCH (n) RETURN n LIMIT 1' ) print(json.dumps(response['results'], indent=2))

有关其他语言的 Amazon SDK 示例,请参阅Amazon SDK

使用 curlawscurl

curl 命令行工具直接向海王星端点提交 HTTP 请求。如果启用了 IAM 身份验证,请使用 awscurl curl 7.75.0+ 并可选择签署请求。--aws-sigv4有关更多信息,请参阅 使用带有临时证书的 awscurl 安全地连接到启用了 IAM 身份验证的数据库集群

为 HT TPS 设置 cur l

要使用 HTTPS 进行连接(正如海王星在大多数地区所要求的那样),curl需要访问相应的证书。有关如何获取证书并将其格式化为证书颁发机构 (CA) 存储的信息,请参阅curl文档中的 SSL 证书验证。

您可以使用CURL_CA_BUNDLE环境变量指定此 CA 证书存储库的位置。在 Windows 上,curl 自动在名为 curl-ca-bundle.crt 的文件中查找它。首先在与 curl.exe 相同的目录中查找,然后在路径的其他位置查找。有关更多信息,请参阅 SSL 证书验证

只要 curl 可以找到相应的证书,它即可像处理 HTTP 连接一样处理 HTTPS 连接,而无需额外的参数。本文档中的示例基于该场景。

有关该工具的更多信息,请参阅 curl 手册页和《Every th ing cur l》一书。

查询示例

以下示例显示如何使用curl和运行基本查询awscurl

Gremlin (awscurl)
awscurl https://your-neptune-endpoint:port/gremlin \ --region us-east-1 \ --service neptune-db \ -X POST \ -d '{"gremlin":"g.V().limit(1)"}'
Gremlin (curl)
curl -X POST \ -d '{"gremlin":"g.V().limit(1)"}' \ https://your-neptune-endpoint:port/gremlin
注意

只有在集群上未启用 IAM 身份验证时,Plain 才有curl效。

openCypher (awscurl)
awscurl https://your-neptune-endpoint:port/openCypher \ --region us-east-1 \ --service neptune-db \ -X POST \ -d "query=MATCH (n) RETURN n LIMIT 1"
openCypher (curl)
curl -X POST \ -d "query=MATCH (n) RETURN n LIMIT 1" \ https://your-neptune-endpoint:port/openCypher
注意

只有在集群上未启用 IAM 身份验证时,Plain 才有curl效。

有关更多 Gremlin HTTP 示例,请参阅。HTTPS REST有关更多 OpenCypher HTTP 示例,请参阅。HTTPS 端点