本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 IAM 身分驗證搭配 Gremlin 主控台連線至 Amazon Neptune 資料庫
使用 Gremlin 主控台搭配 Signature 第 4 版身分驗證來連接 Amazon Neptune 有兩個先決條件:
您必須具有簽署請求所需的 IAM 憑證。請參閱《 適用於 Java 的 AWS SDK 開發人員指南》中的使用預設登入資料提供者鏈結。
您必須已安裝與資料庫叢集所使用的 Neptune 引擎版本相容的 Gemlin 主控台版本。
如果您使用的是臨時憑證,它們會在指定的間隔後過期,而工作階段權杖也一樣,因此在您請求新憑證時必須更新您的工作階段權杖。請參閱《IAM 使用者指南》中的使用臨時安全登入資料來請求存取 AWS 資源。
如需使用 SSL/TLS 進行連線的說明,請參閱 SSL/TLS 組態。
:remote 命令用於從 Gremlin 主控台建立與 Neptune 的連線。您將使用 requestInterceptor()將 Sigv4 簽署者插入該連線,透過 IAM 進行驗證。
請注意,這與 :remote 命令需要組態檔案形成連線的典型情況完全不同。組態檔案方法將無法運作,因為 requestInterceptor() 必須以程式設計方式設定,並且無法從檔案中載入其組態。
使用 Sigv4 簽署來連接 Gremlin 主控台
-
啟動 Gremlin 主控台:
$ bin/gremlin.sh -
在
gremlin>提示中,安裝amazon-neptune-sigv4-signer程式庫 (只需要為主控台完成一次此操作)::install com.amazonaws amazon-neptune-sigv4-signer 2.4.0如果您在此步驟中遇到問題,則參閱有關 Grape
組態的 TinkerPop 文件 可能會有所幫助 。 注意
如果您使用的是 HTTP Proxy,在此步驟中可能會遇到
:install命令未完成的錯誤。若要解決此問題,請執行下列命令,以告知主控台有關 Proxy 的相關資訊:System.setProperty("https.proxyHost", "(the proxy IP address)") System.setProperty("https.proxyPort", "(the proxy port)") -
將處理簽署所需的類別匯入至
requestInterceptor()::import com.amazonaws.auth.DefaultAWSCredentialsProviderChain :import com.amazonaws.neptune.auth.NeptuneNettyHttpSigV4Signer -
如果您使用的是臨時憑證,則還需要提供工作階段權杖,如下所示:
System.setProperty("aws.sessionToken","(your session token)") -
如果您尚未以其他方式建立帳戶憑證,則可以指派它們,如下所示:
System.setProperty("aws.accessKeyId","") System.setProperty("aws.secretKey","(your access key)(your secret key)") -
手動建構要連線至 Neptune 的
Cluster物件:注意
下列範例已更新為包含 requestInterceptor() 的使用。這已在 TinkerPop 3.6.6 中新增。在 TinkerPop 3.6.6 版之前,程式碼範例使用 handshakeInterceptor(),該版本已棄用。
cluster = Cluster.build("(host name)") \ .enableSsl(true) \ .requestInterceptor { r -> \ def sigV4Signer = new NeptuneNettyHttpSigV4Signer("(Amazon region)", \ new DefaultAWSCredentialsProviderChain()); \ sigV4Signer.signRequest(r); \ return r; } \ .create()如需尋找 Neptune 資料庫執行個體主機名稱的說明,請參閱 連線至 Amazon Neptune 端點。
-
使用上一個步驟中
Cluster物件的變數名稱來建立:remote連線::remote connect tinkerpop.server cluster -
輸入以下命令以切換至遠端模式。這會將所有 Gremlin 查詢傳送至遠端連線:
:remote console