Skip to content

Instantly share code, notes, and snippets.

@vre
Created June 9, 2017 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vre/997b336499824a0e56999d030dce321a to your computer and use it in GitHub Desktop.
Save vre/997b336499824a0e56999d030dce321a to your computer and use it in GitHub Desktop.
Small tool to read any kinesis stream you have
#!/bin/bash
# Reads and outputs Kinesis stream given as argument
# For oneliner see https://gist.github.com/vre/7ee11edb765bf9bbdf1ad4ab1790c7c1
# Based on https://gist.github.com/LarsFronius/e579051d7f140fd803b0
if [ -z "$1" ]; then
echo "This script outputs AWS Kinesis stream as ASCII"
echo "Usage: $0 <stream name>"
echo
echo "Available streams: `aws kinesis list-streams --output text | cut -f 2-`"
exit 1
fi
streamname=$1;
aws kinesis describe-stream --stream-name $streamname --output text | grep SHARDS | awk '{print $2}' | \
while read shard; do
aws kinesis get-shard-iterator --stream-name $streamname --shard-id $shard --shard-iterator-type LATEST --output text | \
while read iterator; do
while output=`aws kinesis get-records --shard-iterator $iterator --output text`; do
iterator=`echo "$output" | head -n1 | awk '{print $2}'`; echo "$output" | awk 'NR > 1' | grep RECORDS | \
while read record; do
echo $record | awk '{print $3}' | base64 -D;
done;
done;
done;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment