View a markdown version of this page

Neptune ストリームデータの読み取り - Amazon Neptune

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

Neptune ストリームデータの読み取り

次の例は、プロパティグラフストリームエンドポイントからレコードを読み取る方法を示しています。 AWS CLI、 AWS SDK for Python (Boto3)、awscurl、または を使用できますcurl

AWS CLI
aws neptunedata get-propertygraph-stream \ --endpoint-url https://your-neptune-endpoint:port \ --iterator-type TRIM_HORIZON \ --limit 10

ストリーム内の特定の位置から読み取るには、 パラメータ--commit-num--iterator-typeパラメータを使用します。

aws neptunedata get-propertygraph-stream \ --endpoint-url https://your-neptune-endpoint:port \ --limit 10 \ --commit-num 1 \ --iterator-type AT_SEQUENCE_NUMBER

詳細については、 AWS CLI 「 コマンドリファレンス」のget-propertygraph-stream」を参照してください。

SDK (Python)
import boto3 import json from botocore.config import Config client = boto3.client( 'neptunedata', region_name='us-east-1', endpoint_url='https://your-neptune-endpoint:port', config=Config(read_timeout=65) ) response = client.get_propertygraph_stream( limit=10, iteratorType='TRIM_HORIZON' ) print(json.dumps(response['records'], indent=2, default=str))

ストリームをページ分割するには、レスポンスlastEventIdopNumから commitNumと を使用します。

last_event = response['lastEventId'] next_response = client.get_propertygraph_stream( limit=10, commitNum=last_event['commitNum'], opNum=last_event['opNum'], iteratorType='AFTER_SEQUENCE_NUMBER' )
awscurl
awscurl https://your-neptune-endpoint:port/propertygraph/stream?limit=10 \ --region us-east-1 \ --service neptune-db
注記

この例では、 AWS 認証情報が 環境で設定されていることを前提としています。us-east-1 を Neptune クラスターのリージョンに置き換えます。

IAM 認証awscurlで を使用する方法の詳細については、「」を参照してください一時的な認証情報で awscurl を使用して、IAM 認証が有効になっている DB クラスターに安全に接続する

curl
curl https://your-neptune-endpoint:port/propertygraph/stream?limit=10
注記

SigV4 署名curlなしで を使用すると、Neptune クラスターで IAM 認証が無効になっている場合にのみ機能します。IAM 認証が有効になっている場合は、 AWS CLI 代わりに awscurlまたは を使用します。

SPARQL グラフの場合は、前の例/sparql/stream/propertygraph/streamを に置き換えます。 AWS CLI または SDK を使用する場合は、client.get_sparql_stream()代わりに get-sparql-streamまたは を使用します。

グラフノートブックでのストリームデータの表示

Neptune グラフノートブックを使用する場合、%stream_viewerラインマジックは、コードを記述せずにストリームレコードをインタラクティブに参照するためのビジュアルインターフェイスを提供します。ノートブックセルで以下を実行します。

%stream_viewer

オプションで、クエリ言語とページサイズを指定できます。

%stream_viewer sparql --limit 20

詳細については、「%stream_viewer ラインマジック」を参照してください。

注記

%stream_viewer マジックは、エンジンバージョン 1.0.5.1 以前でのみ完全にサポートされています。