Skip to content

Instantly share code, notes, and snippets.

@senderista
Last active September 17, 2015 16:45
Show Gist options
  • Select an option

  • Save senderista/904f52f08241b67eba8d to your computer and use it in GitHub Desktop.

Select an option

Save senderista/904f52f08241b67eba8d to your computer and use it in GitHub Desktop.
View incoming records in a Kinesis stream in real time
#!/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