Skip to content

Instantly share code, notes, and snippets.

@yuta-imai
Last active August 29, 2015 14:05
Show Gist options
  • Save yuta-imai/ef57a00bb4f952e655b2 to your computer and use it in GitHub Desktop.
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.
#!/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