Last active
August 29, 2015 14:05
-
-
Save yuta-imai/ef57a00bb4f952e655b2 to your computer and use it in GitHub Desktop.
A code snippet to pull records from Amazon Kinesis and dump it.
This file contains hidden or 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 python | |
import base64 | |
import time | |
import sys | |
import boto | |
import boto.kinesis | |
region = 'ap-northeast-1' | |
stream_name = sys.argv[1] | |
shard_number = int(sys.argv[2]) | |
conn = boto.kinesis.connect_to_region(region) | |
stream = conn.describe_stream(stream_name) | |
shard = stream['StreamDescription']['Shards'][shard_number]['ShardId'] | |
i = conn.get_shard_iterator(stream_name, shard, 'LATEST') | |
iterator = i['ShardIterator'] | |
while True: | |
result = conn.get_records(iterator,1000,True) | |
for record in result['Records']: | |
print record['Data'].decode('base64') | |
iterator = result['NextShardIterator'] | |
time.sleep(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment