Neptune 公有端點 - Amazon Neptune

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

Neptune 公有端點

概觀

Amazon Neptune 叢集通常部署在您的 VPC 內,並且只能在該 VPC 內存取。這需要在 VPC 內設定應用程式和開發環境,或使用代理服務連接到 VPC,這會增加設定時間和成本。

公有端點允許透過網際網路直接連線至 Neptune 來簡化此體驗,讓您更輕鬆地開始使用圖形資料庫,而無需專門的網路知識。

何時使用公有端點

在下列案例中考慮使用公有端點:

  • 您想要在沒有複雜網路組態的情況下,在開發或測試環境中快速測試 Neptune

  • 您沒有專業的 AWS 聯網知識

  • 您應用程式的安全狀態不需要私有 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 (網路設定)

  1. 確保您的 VPC 具有啟用公有路由的子網路 (子網路路由表中的網際網路閘道項目)。如果您在建立叢集時未提供db-subnet-group-name參數,則會選擇預設子網路群組來建立叢集。

  2. 確定連接到叢集的安全群組允許允許 IP 範圍和允許連接埠的傳入流量。例如,如果您想要允許來自所有 IPs TCP 流量連線到連接埠 8182 上執行的 Neptune 執行個體,傳入規則應該具有:

    1. 類型:所有 TCP

    2. Protocol (通訊協定):TCP

    3. 連接埠範圍:8182

    4. CIDR 區塊:0.0.0.0/0

注意

雖然您可以將 CIDR 區塊範圍設定為 0.0.0.0/0,但建議您將此範圍縮減為用戶端應用程式的特定 IP 範圍,以獲得更好的安全狀態。

使用公有端點建立新的執行個體

您可以使用 AWS 管理主控台、 AWS CLI 或 AWS SDK,使用公有端點建立新的 Neptune 執行個體。

使用 AWS CLI:

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
注意

公有存取是在執行個體層級啟用,而非叢集層級。為了確保您的叢集一律可透過公有端點存取,叢集中的所有執行個體都必須啟用公有存取。

使用公有端點

若要檢查您的資料庫是否可連線,請使用 CLI NeptuneData API AWS 檢查狀態:

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" } }

如何查詢資料庫的範例

AWS 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 AWS 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 地址。

  • 存取是由指派給叢集的安全群組所控制。

  • 只有可公開存取的執行個體才能透過網際網路存取。

讀取器端點行為

  • 如果所有讀取器執行個體都可公開存取,讀取器端點一律會透過公有網際網路解析。

  • 如果只有某些讀取器執行個體可供公開存取,則只有在讀取器端點選取可公開存取的執行個體來提供讀取查詢時,讀取器端點才會公開解析。

叢集端點行為

  • 資料庫叢集端點一律會解析為寫入器的執行個體端點。

  • 如果在寫入器執行個體上啟用公有端點,叢集端點將可公開存取,否則將無法公開存取。

叢集容錯移轉之後的行為

  • Neptune 叢集可以在不同的可公開存取設定上擁有執行個體。

  • 如果叢集具有公有寫入器和非公有讀取器,請發佈叢集容錯移轉,新的寫入器 (先前的讀取器) 會變成非公有,而新的讀取器 (先前的寫入器) 會變成公有。

網路組態需求

若要讓公有端點正常運作:

  1. Neptune 執行個體必須位於 VPC 內的公有子網路中。

  2. 與這些子網路相關聯的路由表必須具有 0.0.0.0/0 的網際網路閘道路由。

  3. 安全群組必須允許從您要授予存取權的公有 IP 地址或 CIDR 範圍進行存取。

限制公有存取建立

您可以使用 IAM 政策來限制誰可以建立或修改具有公有存取權的 Neptune 叢集。下列範例政策拒絕建立具有公有存取權的 Neptune 執行個體:

JSON
{ "Version":"2012-10-17", "Statement": [ { "Effect": "Deny", "Action": [ "rds:CreateDBInstance", "rds:ModifyDBInstance", "rds:RestoreDBInstanceFromDBSnapshot", "rds:RestoreDBInstanceToPointInTime" ], "Resource": "*", "Condition": { "Bool": { "rds:PubliclyAccessible": true } } } ] }

IAM rds:PublicAccessEnabled 條件金鑰的詳細資訊:Amazon RDS Service 授權參考

AWS CloudFormation 支援

您可以使用 在 AWS CloudFormation 範本中指定 PubliclyAccessible 參數, AWS CloudFormation 以啟用公有端點來啟動 Neptune 叢集。

與 Neptune 功能的相容性

啟用公有端點的叢集支援僅限 VPC 叢集支援的所有 Neptune 功能,包括:

  • Neptune 工作台

  • 全文搜尋整合

  • Neptune 串流

  • 自訂端點

  • Neptune Serverless

  • 圖形總管

定價

除了標準 Neptune 定價之外,可免費使用公有端點。不過,透過公有 IP 從本機環境連線至 Neptune 可能會增加資料傳輸成本。