-
Notifications
You must be signed in to change notification settings - Fork 0
/
aux.py
74 lines (49 loc) · 2.09 KB
/
aux.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import boto3
import time
import datetime
from dateutil.tz import tzlocal
stream_name = "test"
records_per_read = 100
timest = datetime.datetime(2016, 5, 26, 21, 29, 51, 30000)
initial_position = "TRIM_HORIZON" # or "LATEST"
sequence_number = "49563739517273067749522882060982940426021036387060416642"
def get_shard_iterators(kin):
'''Function which gets iterators for all shards'''
shard_ids = []
stream = kin.describe_stream(StreamName=stream_name)
for shard in stream["StreamDescription"]["Shards"]:
shard_id = shard["ShardId"]
# UTILIZAR SOLO UNO DE LOS SIGUIENTES ITERADORES. MANTENER EL RESTO COMENTADO
# Shard Iterator por TrimHorizon o Latest
shard_iterator = kin.get_shard_iterator(StreamName=stream_name, ShardIteratorType=initial_position, ShardId=shard_id)
# Shard Iterator por SequenceNumber
#shard_iterator = kin.get_shard_iterator(StreamName=stream_name, ShardIteratorType="AT_SEQUENCE_NUMBER", StartingSequenceNumber='49562325717353430662378673540711573757306106601036316722', ShardId=shard_id)
# Shard Iterator por Timestamp
#shard_iterator = kin.get_shard_iterator(StreamName=stream_name, ShardIteratorType="AT_TIMESTAMP", Timestamp=timest, ShardId=shard_id)
shard_ids.append({'shard_id' : shard_id ,'shard_iterator' : shard_iterator['ShardIterator'] })
return shard_ids
def main():
kin = boto3.client('kinesis')
shard_ids = get_shard_iterators(kin)
#print shards_ids
tries = 0
while tries < 1000000:
tries += 1
msg = ""
msg += "\n"
msg += "######################################\n"
msg += ">>>>>>>> Iteracion {0}\n".format(tries)
for shard in shard_ids:
msg += "\n"
msg += ">>>>> {0}\n".format(shard["shard_id"])
#Obten el primer elemento
out = kin.get_records(ShardIterator=shard["shard_iterator"], Limit=records_per_read)
if "NextShardIterator" in out:
shard["shard_iterator"] = out["NextShardIterator"]
msg += "Numero de registros: {}\n".format(len(out["Records"]))
if len(out["Records"]) > 0:
msg += "{}\n".format(out["Records"][0])
msg += "######################################\n"
msg += "\n"
print msg
time.sleep(2)