Last active
September 17, 2015 16:45
-
-
Save senderista/904f52f08241b67eba8d to your computer and use it in GitHub Desktop.
View incoming records in a Kinesis stream in real time
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 sys | |
| import boto.kinesis | |
| region, stream = sys.argv[1:3] | |
| kinesis = boto.kinesis.connect_to_region(region) | |
| response = kinesis.describe_stream(stream) | |
| if response['StreamDescription']['StreamStatus'] == 'ACTIVE': | |
| shard_id = response['StreamDescription']['Shards'][0]['ShardId'] | |
| else: | |
| raise 'Stream not active, aborting...' | |
| response = kinesis.get_shard_iterator(stream, shard_id, 'LATEST') | |
| shard_iterator = response['ShardIterator'] | |
| while True: | |
| response = kinesis.get_records(shard_iterator) | |
| shard_iterator = response['NextShardIterator'] | |
| for record in response['Records']: | |
| print record['Data'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment