-
Notifications
You must be signed in to change notification settings - Fork 0
/
consumer.py
28 lines (25 loc) · 1021 Bytes
/
consumer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from boto import kinesis
import time
kinesis = kinesis.connect_to_region("us-west-2")
stream_name = "TestStream"
tries = 0
while tries < 100:
tries += 1
try:
response = kinesis.describe_stream(stream_name)
#print(response)
if response['StreamDescription']['StreamStatus'] == 'ACTIVE':
print("stream is active")
shards = response['StreamDescription']['Shards']
for shard in shards:
shard_id = shard["ShardId"]
print (repr(shard))
shard_it = kinesis.get_shard_iterator(stream_name, shard_id, "LATEST")["ShardIterator"]
while True:
out = kinesis.get_records(shard_it, limit=2)
for o in out["Records"]:
print (o["Data"])
# You specific data processing goes here
shard_it = out["NextShardIterator"]
except:
print('error while trying to describe kinesis stream : %s')