Skip to main content

PyPI version Python versions Docker version Build Status

aws-kinesis-consumer

Consume an AWS Kinesis Data Stream to look over the records from a terminal.

Demo

$ 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

Usage

Pre-requirement

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.

Use with Python

# install
pip install aws-kinesis-consumer

# consume a stream
aws-kinesis-consumer --stream-name MyStream

Use with Docker

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

Arguments

Default Description
-s --stream-name REQUIRED Name of the AWS Kinesis Stream.
-e --endpoint Custom AWS endpoint url to communicate with the AWS API. Could be used in order to specify a region (e.g. https://kinesis.us-east-1.amazonaws.com/).
-i --iterator-type latest Defines how to start consuming records from the stream. Use latest to consume the new records only. Or use trim-horizon to consume all the records already existing in the stream.
-m --max-records-per-request 10 Defines the maximum number of records per request.
-r --region AWS region of the stream (e.g. us-east-1). By default, the AWS region available in your terminal (e.g. environment variable AWS_DEFAULT_REGION).
-h --help Prints the help message.
-V --verbose Prints all the details when an error stops the application.
-v --version Prints the version of the binary.

FAQ

What is the motivation ? What is the issue with AWS CLI ?

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.

How to filter the records ?

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"}

What are the required AWS permissions ?

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"
            ]
        }
    ]
}

How to contribute to the project ?

See the guidelines in the CONTRIBUTING.md file .

Changelog

See all the changes per release.

Special thanks

  • Thanks to the contributors of the kinesalite project which make test and development of this project extremely easy and reliable!

Release files for aws-kinesis-consumer 1.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-kinesis-consumer 1.4.1
File Size Uploaded
aws-kinesis-consumer-1.4.1.tar.gz 17.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-kinesis-consumer 1.4.1
File Interpreter ABI Platform
aws_kinesis_consumer-1.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 43.0 kB

Release files / aws-kinesis-consumer-1.4.1.tar.gz

Download URL aws-kinesis-consumer-1.4.1.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
18037e7d1f518ccffe2b611667eb9e4ab55978a3fb1c918da6a229928940883a
BLAKE2b-256 checksum
How to use checksums
82d48d388c98596c3b4971ebc657417404947883abac25409dfd65b357fc9286
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.8.2 requests/2.27.1 setuptools/60.10.0 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.7.1

Release files / aws_kinesis_consumer-1.4.1-py3-none-any.whl

Download URL aws_kinesis_consumer-1.4.1-py3-none-any.whl
Size 25.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
389e3c304600b9d8a67194bd471824ae7e3234adddc891b57ba15f7af76539c4
BLAKE2b-256 checksum
How to use checksums
f12f64b02f367a98be222944ac779ffa83e315981eef4f123bfad2e1300c77bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.8.2 requests/2.27.1 setuptools/60.10.0 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.7.1

Release history Release notifications | RSS feed

This release

1.4.1 This release

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page