Consume an AWS Kinesis Data Stream to look over the records from a terminal.
$ aws-kinesis-consumer --stream-name MyStream
> preparing shards 2/2
> shard_id=shardId-000000000000, records=1
Record-001
> shard_id=shardId-000000000001, records=2
Record-002
Record-003
Connect to AWS and set the default AWS environment variables .
export AWS_DEFAULT_REGION=eu-central-1
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Alternatively, aws configure can help to set the environment variables.
# install
pip install aws-kinesis-consumer
# consume a stream
aws-kinesis-consumer --stream-name MyStream
docker run \
-e AWS_DEFAULT_REGION \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
-e AWS_SESSION_TOKEN \
thinow/aws-kinesis-consumer --stream-name MyStream
The AWS CLI is able to fetch records from Kinesis, but the users need to list the shards, to generate iterator tokens, use subsequent tokens, delay operations, and so on.
aws-kinesis-consumer
in contrary is able to get records by using the stream name, and only the stream name. Therefore
there is no need for an extra script.
aws-kinesis-consumer
can be piped with other command such as grep,
or even jq to filter json records.
# all the records
$ aws-kinesis-consumer --stream-name MyStream
{"name":"foo", "status":"ok"}
{"name":"bar", "status":"pending"}
{"name":"baz", "status":"error"}
# records containing the text "ba" (e.g. "bar" and "baz", but not "foo")
$ aws-kinesis-consumer --stream-name MyStream | grep "ba"
{"name":"bar", "status":"pending"}
{"name":"baz", "status":"error"}
# records where the json property "status" has the value "error"
$ aws-kinesis-consumer --stream-name MyStream | jq 'select(.status == "error")'
{"name":"baz", "status":"error"}
aws-kinesis-consumer
requires the following AWS permissions :
The following policy is an example which can be applied to an AWS user or an AWS role :
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"kinesis:ListShards",
"kinesis:GetShardIterator",
"kinesis:GetRecords"
],
"Resource": [
"arn:aws:kinesis:REGION:ACCOUNT-ID:stream/STREAM-NAME"
]
}
]
}
See the guidelines in the CONTRIBUTING.md file .
See all the changes per release.
- Thanks to the contributors of the kinesalite project which make test and development of this project extremely easy and reliable!