Skip to content

Instantly share code, notes, and snippets.

@noamtamim
Created April 18, 2021 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noamtamim/68e91c14f84b4456dec3638743268fbf to your computer and use it in GitHub Desktop.
Save noamtamim/68e91c14f84b4456dec3638743268fbf to your computer and use it in GitHub Desktop.
Kinesis Stream Reader
#!/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