

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

# Neptune ストリームデータの読み取り
<a name="streams-using-reading"></a>

次の例は、プロパティグラフストリームエンドポイントからレコードを読み取る方法を示しています。 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](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/get-propertygraph-stream.html)」を参照してください。

------
#### [ 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))
```

ストリームをページ分割するには、レスポンス`lastEventId`で `opNum`から `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 クラスターに安全に接続する](iam-auth-connect-command-line.md#iam-auth-connect-awscurl)。

------
#### [ 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`または を使用します。

## グラフノートブックでのストリームデータの表示
<a name="streams-using-notebook"></a>

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

```
%stream_viewer
```

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

```
%stream_viewer sparql --limit 20
```

詳細については、「[`%stream_viewer` ラインマジック](notebooks-magics.md#notebooks-line-magics-stream-viewer)」を参照してください。

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