本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
Neptune 公共端点
概览
Amazon Neptune 集群通常部署在您的 VPC 内,并且只能从该 VPC 内部进行访问。这需要在 VPC 中配置应用程序和开发环境,或者使用代理服务连接到 VPC,这会增加设置时间和成本。
公共端点允许通过互联网直接连接到 Neptune,从而简化了这种体验,无需专业网络知识即可更轻松地开始使用图形数据库。
何时使用公共终端节点
考虑在以下情况下使用公共终端节点:
-
您想在开发或测试环境中快速测试 Neptune,无需复杂的网络配置
-
你没有专业的 Amazon 网络知识
-
您的应用程序的安全状况不需要私有 VPC
-
你需要从本地开发环境连接到 Neptune
安全性注意事项
使用公共端点时,请记住以下安全注意事项:
-
启用了公共终端节点的集群需要 IAM 身份验证。
-
对数据库的访问由其使用的安全组控制。
-
您可以限制哪些 IP 地址可以连接到您的集群。
-
您可以使用 IAM 策略来控制谁可以创建或修改具有公共访问权限的集群。请参阅:限制公共访问权限的创建
启用公共终端节点
默认情况下,新的 Neptune 数据库是在禁用公共端点的情况下创建的。创建或修改集群时,必须明确启用公共访问权限。
Neptune 引擎发行版 1.4.6.x 支持公共端点。您需要将现有集群至少升级到此版本才能使用此功能。
公共终端节点设置在 Neptune 实例上可用,而不是 Neptune 集群。因此,Neptune 集群可能存在一些带有公共终端节点的实例,而有些则没有公共终端节点。但是,我们不建议使用这样的设置。有关这方面的更多信息,请参阅:公共端点的工作原理
先决条件
Neptune 集群上的 IAM 身份验证设置
在 Neptune 实例上启用公共终端节点之前,请确保您的集群支持 IAM 身份验证。如果不是,请使用以下命令将其启用:
aws neptune modify-db-cluster \ --region us-west-2 \ --engine graphdb \ --engine-version 1.4.6.x \ --db-cluster-identifier neptune-public-endpoint \ --enable-iam-database-authentication
Network settings (网络设置)
-
确保您的 VPC 具有启用公共路由的子网(子网的路由表中有 Internet 网关的条目)。如果您在创建集群时未提供
db-subnet-group-name
参数,则会选择默认子网组来创建集群。 -
确保连接到集群的安全组允许允许的 IP 范围和允许的端口的入站流量。例如,如果您要允许来自所有的 TCP 流量 IPs 连接到在端口 8182 上运行的 Neptune 实例,则入站规则应具有:
-
类型:全部 TCP
-
协议:TCP
-
端口范围:8182
-
CIDR 区块:0.0.0.0/0
-
注意
尽管您可以将 CIDR 块范围设置为 0.0.0.0/0,但我们建议将其缩小到客户端应用程序的特定 IP 范围,以获得更好的安全状态。
使用公共终端节点创建新实例
您可以使用 Amazon 管理控制台、CL Amazon I 或 Amazon SDK 创建带有公共终端节点的新 Neptune 实例。
使用 C Amazon LI:
aws neptune create-db-instance \ --region us-west-2 \ --engine graphdb \ --engine-version 1.4.6.x \ --db-cluster-identifier neptune-public-endpoint \ --publicly-accessible
修改现有实例以供公有访问
要修改现有 Neptune 实例以启用公共访问,请执行以下操作:
aws neptune modify-db-instance \ --region us-west-2 \ --engine graphdb \ --engine-version 1.4.6.x \ --db-instance-identifier neptune-public-endpoint \ --publicly-accessible
注意
公共访问是在实例级别而不是集群级别启用的。为确保您的集群始终可通过公共终端节点进行访问,集群中的所有实例都必须启用公有访问权限。
使用公共终端节点
要检查您的数据库是否可以访问,请使用 Amazon CLI NeptuneData
API 检查状态:
aws neptunedata get-engine-status \ --endpoint-url https://my-cluster-name.cluster-abcdefgh1234.us-east-1.neptune.amazonaws.com:8182
如果数据库可以访问,则响应如下所示:
{ "status": "healthy", "startTime": "Sun Aug 10 06:54:15 UTC 2025", "dbEngineVersion": "1.4.6.0.R1", "role": "writer", "dfeQueryEngine": "viaQueryHint", "gremlin": { "version": "tinkerpop-3.7.1" }, "sparql": { "version": "sparql-1.1" }, "opencypher": { "version": "Neptune-9.0.20190305-1.0" }, "labMode": { "ObjectIndex": "disabled", "ReadWriteConflictDetection": "enabled" }, "features": { "SlowQueryLogs": "disabled", "InlineServerGeneratedEdgeId": "disabled", "ResultCache": { "status": "disabled" }, "IAMAuthentication": "disabled", "Streams": "disabled", "AuditLog": "disabled" }, "settings": { "StrictTimeoutValidation": "true", "clusterQueryTimeoutInMs": "120000", "SlowQueryLogsThreshold": "5000" } }
如何查询数据库的示例
Amazon CLI
aws neptunedata execute-open-cypher-query \ --open-cypher-query "MATCH (n) RETURN n LIMIT 10" \ --endpoint-url https://my-cluster-name.cluster-abcdefgh1234.us-east-1.neptune.amazonaws.com:8182
Python
import boto3 import json from botocore.config import Config # Configuration - Replace with your actual Neptune cluster details cluster_endpoint = "my-cluster-name.cluster-abcdefgh1234.my-region.neptune.amazonaws.com" port = 8182 region = "my-region" # Configure Neptune client # This disables retries and sets the client timeout to infinite # (relying on Neptune's query timeout) endpoint_url = f"https://{cluster_endpoint}:{port}" config = Config( region_name=region, retries={'max_attempts': 1}, read_timeout=None ) client = boto3.client("neptunedata", config=config, endpoint_url=endpoint_url) cypher_query = "MATCH (n) RETURN n LIMIT 5" try: response = client.execute_open_cypher_query(openCypherQuery=cypher_query) print("openCypher Results:") for item in response.get('results', []): print(f" {item}") except Exception as e: print(f"openCypher query failed: {e}")
JavaScript
import { NeptunedataClient, GetPropertygraphSummaryCommand } from "@aws-sdk/client-neptunedata"; import { inspect } from "util"; import { NodeHttpHandler } from "@smithy/node-http-handler"; /** * Main execution function */ async function main() { // Configuration - Replace with your actual Neptune cluster details const clusterEndpoint = 'my-cluster-name.cluster-abcdefgh1234.my-region.neptune.amazonaws.com'; const port = 8182; const region = 'my-region'; // Configure Neptune client // This disables retries and sets the client timeout to infinite // (relying on Neptune's query timeout) const endpoint = `https://${clusterEndpoint}:${port}`; const clientConfig = { endpoint: endpoint, sslEnabled: true, region: region, maxAttempts: 1, // do not retry requestHandler: new NodeHttpHandler({ requestTimeout: 0 // no client timeout }) }; const client = new NeptunedataClient(clientConfig); try { try { const command = new GetPropertygraphSummaryCommand({ mode: "basic" }); const response = await client.send(command); console.log("Graph Summary:", inspect(response.payload, { depth: null })); } catch (error) { console.log("Property graph summary failed:", error.message); } } catch (error) { console.error("Error in main execution:", error); } } // Run the main function main().catch(console.error);
Go
package main import ( "context" "fmt" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/service/neptunedata" "os" "encoding/json" "net/http" ) func main() { // Configuration - Replace with your actual Neptune cluster details clusterEndpoint := "my-cluster-name.cluster-abcdefgh1234.my-region.neptune.amazonaws.com" port := 8182 region := "my-region" // Configure Neptune client // Configure HTTP client with no timeout // (relying on Neptune's query timeout) endpoint := fmt.Sprintf("https://%s:%d", clusterEndpoint, port) // Load Amazon SDK configuration sdkConfig, _ := config.LoadDefaultConfig( context.TODO(), config.WithRegion(region), config.WithHTTPClient(&http.Client{Timeout: 0}), ) // Create Neptune client with custom endpoint client := neptunedata.NewFromConfig(sdkConfig, func(o *neptunedata.Options) { o.BaseEndpoint = aws.String(endpoint) o.Retryer = aws.NopRetryer{} // Do not retry calls if they fail }) gremlinQuery := "g.addV('person').property('name','charlie').property(id,'charlie-1')" serializer := "application/vnd.gremlin-v1.0+json;types=false" gremlinInput := &neptunedata.ExecuteGremlinQueryInput{ GremlinQuery: &gremlinQuery, Serializer: &serializer, } gremlinResult, err := client.ExecuteGremlinQuery(context.TODO(), gremlinInput) if err != nil { fmt.Printf("Gremlin query failed: %v\n", err) } else { var resultMap map[string]interface{} err = gremlinResult.Result.UnmarshalSmithyDocument(&resultMap) if err != nil { fmt.Printf("Error unmarshaling Gremlin result: %v\n", err) } else { resultJSON, _ := json.MarshalIndent(resultMap, "", " ") fmt.Printf("Gremlin Result: %s\n", string(resultJSON)) } } }
公共端点的工作原理
当 Neptune 实例可以公开访问时:
-
它的 DNS 终端节点从数据库集群的 VPC 内解析为私有 IP 地址。
-
它会从集群的 VPC 外部解析为公有 IP 地址。
-
访问由分配给集群的安全组控制。
-
只有可公开访问的实例才能通过互联网访问。
读取器端点行为
-
如果所有读取器实例均可公开访问,则读取器端点将始终通过公共 Internet 进行解析。
-
如果只有一些读取器实例可以公开访问,则只有当读取器终端节点选择可公开访问的实例来提供读取查询时,它才会公开解析。
集群终端节点行为
-
数据库集群终端节点始终解析为写入器的实例终端节点。
-
如果在写入器实例上启用了公共终端节点,则集群终端节点将可公开访问,否则将不可访问。
群集故障转移后的行为
-
Neptune 集群可以将实例设置为不同的公共可访问设置。
-
如果集群有公共写入器和非公共读取器,则在群集故障转移后,新的写入器(以前的读取器)变为非公开读取器,而新的读取器(以前的写入器)变为公开。
网络配置要求
要使公共端点正常工作,请执行以下操作:
-
Neptune 实例必须位于您的 VPC 内的公有子网中。
-
与这些子网关联的路由表必须有通往 0.0.0.0/0 的互联网网关的路由。
-
安全组必须允许从您想要授予访问权限的公有 IP 地址或 CIDR 范围进行访问。
限制公共访问权限的创建
您可以使用 IAM 策略来限制谁可以创建或修改具有公共访问权限的 Neptune 集群。以下示例策略拒绝创建具有公共访问权限的 Neptune 实例:
有关 rds:PublicAccessEnabled
IAM 条件密钥的更多信息:A mazon RDS 服务授权参考
Amazon CloudFormation 支持
通过在模板中指定PubliclyAccessible
参数 Amazon CloudFormation ,您可以使用启动启用公共终端节点的 Neptune Amazon CloudFormation 集群。
与 Neptune 功能的兼容性
启用公共终端节点的集群支持仅限 VPC 的集群支持的所有Neptune功能,包括:
-
Neptune 工作台
-
全文搜索集成
-
Neptune Streams
-
自定义端点
-
Neptune 无服务器
-
图表浏览器
定价
除了标准的 Neptune 定价外,公共端点无需支付任何额外费用。但是,通过公共 IP 从本地环境连接到 Neptune 可能会增加数据传输成本。