-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_sink.sh
61 lines (51 loc) · 1.69 KB
/
validate_sink.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# Version 1.0.0
# Copyright © 2021-23, KORE Wireless
# Licence: MIT
JQ_CHECK=$(which jq)
if [ -z "$JQ_CHECK" ]; then
echo
echo "This script requires the jq JSON processor. Please install for your OS from https://stedolan.github.io/jq/download/"
echo
exit 1
fi
if [ $# -ne 1 ]; then
echo
echo "usage: $0 <stream_name>"
echo
exit 1
fi
# Set the stream name
STREAM_NAME=$1
# Choose the iterator type:
# TRIM HORIZON is for starting at the begining of the Kinesis Stream.
# This can take a while if you have a lot of records.
# To use TRIM HORIZON, uncomment the following line:
# TYPE=TRIM_HORIZON
# AT_TIMESTAMP allows you to go back to a point in time. This is set for going back one hour
# To use AT_TIMESTAMP, uncomment the following two lines:
# TIMESTAMP=$(($(date +%s) - 3600)).000
# TYPE="AT_TIMESTAMP --timestamp $TIMESTAMP"
# LATEST means start at the most current point in the stream and read forward
TYPE=LATEST
# Get a list of shards
SHARDS=$(aws kinesis list-shards --stream-name $STREAM_NAME | jq -r .Shards[].ShardId)
# Get all the starting points
SHARD_ITERATOR=()
i=0
for shard in $SHARDS ; do
SHARD_ITERATOR[$i]=$(aws kinesis get-shard-iterator --shard-id $shard --shard-iterator-type $TYPE --stream-name $STREAM_NAME --query 'ShardIterator')
i=$((i+1))
done
# Start getting events from all shards and display them
while [ 1 ] ; do
len=${#SHARD_ITERATOR[@]}
for (( i=0; i < $len; i++ )); do
DATA=$(aws kinesis get-records --limit 50 --shard-iterator ${SHARD_ITERATOR[$i]})
SHARD_ITERATOR[$i]=$(echo $DATA | jq -r .NextShardIterator)
ROWS=$(echo $DATA | jq -r .Records[].Data?)
for row in $ROWS; do
echo $row | base64 -d | jq .
done
done
done