Created
April 18, 2021 13:46
-
-
Save noamtamim/68e91c14f84b4456dec3638743268fbf to your computer and use it in GitHub Desktop.
Kinesis Stream Reader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import boto3 | |
import time | |
from pprint import pprint | |
import json | |
import sys | |
client = boto3.client('kinesis') | |
stream_name, shard_id = sys.argv[1:] | |
it = client.get_shard_iterator(StreamName=stream_name, | |
ShardId=shard_id, | |
ShardIteratorType='LATEST')['ShardIterator'] | |
while it: | |
rec = client.get_records(ShardIterator=it) | |
recs = rec['Records'] | |
for r in recs: | |
pprint(json.loads(r['Data'].decode('utf8'))) | |
it = rec['NextShardIterator'] | |
if not recs: | |
print('Waiting for data...') | |
time.sleep(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment