翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
Gremlin Python による IAM 認証を使用した Amazon Neptune データベースへの接続
概要
このガイドでは、Gremlin Python ドライバーを使用して IAM 認証を有効にし、署名バージョン 4 認証と AWS SDK for Python (Boto3) を使用して Amazon Neptune データベースに接続する方法を示します。
基本的な接続を作成する
Gremlin Python ドライバーを使用して IAM 認証との基本的な接続を確立する方法のガイダンスとして、次のコード例を使用します。
from boto3 import Session from botocore.auth import SigV4Auth from botocore.awsrequest import AWSRequest from gremlin_python.process.anonymous_traversal import traversal from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection def main(): endpoint = '
your.cluster.endpoint
.neptune.amazonaws.com' conn_string = 'wss://' + endpoint + ':8182/gremlin' default_region = 'us-east-1' service = 'neptune-db' credentials = Session().get_credentials() if credentials is None: raise Exception("No AWS credentials found") creds = credentials.get_frozen_credentials() # region set inside config profile or via AWS_DEFAULT_REGION environment variable will be loaded region = Session().region_name if Session().region_name else default_region request = AWSRequest(method='GET', url=conn_string, data=None) SigV4Auth(creds, service, region).add_auth(request) rc = DriverRemoteConnection(conn_string, 'g', headers=request.headers.items()) g = traversal().with_remote(rc) # simple query to verify connection count = g.V().count().next() print('Vertex count: ' + str(count)) # cleanup rc.close() if __name__ == "__main__": main()