|
| 1 | +# CLI Reference |
| 2 | + |
| 3 | +The `async-kinesis` CLI provides commands for interacting with Kinesis streams from the terminal. It uses the library's Consumer and Producer classes directly, giving you the same deaggregation, serialization, rate limiting, and reconnection logic as the Python API. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +pip install async-kinesis[cli] |
| 9 | +``` |
| 10 | + |
| 11 | +This installs Click as a dependency and registers the `async-kinesis` console script. |
| 12 | + |
| 13 | +## Global Options |
| 14 | + |
| 15 | +``` |
| 16 | +async-kinesis [OPTIONS] COMMAND [ARGS]... |
| 17 | +``` |
| 18 | + |
| 19 | +| Option | Env Var | Description | |
| 20 | +| --- | --- | --- | |
| 21 | +| `--endpoint-url` | `ENDPOINT_URL` | Kinesis endpoint URL (for LocalStack, kinesalite, etc.) | |
| 22 | +| `--region` | `AWS_DEFAULT_REGION` | AWS region name | |
| 23 | +| `-v, --verbose` | | Enable debug logging (shows library internals) | |
| 24 | +| `--version` | | Show version and exit | |
| 25 | + |
| 26 | +AWS credentials are read from the standard boto3 chain (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `~/.aws/credentials`, etc.). |
| 27 | + |
| 28 | +## Commands |
| 29 | + |
| 30 | +### `list` |
| 31 | + |
| 32 | +List Kinesis streams in the account/region. |
| 33 | + |
| 34 | +```bash |
| 35 | +async-kinesis list [--limit N] |
| 36 | +``` |
| 37 | + |
| 38 | +| Option | Default | Description | |
| 39 | +| --- | --- | --- | |
| 40 | +| `--limit` | 100 | Maximum number of streams to return | |
| 41 | + |
| 42 | +Handles both AWS (StreamSummaries with status/shard count/mode) and kinesalite (StreamNames-only) response formats. |
| 43 | + |
| 44 | +**Example:** |
| 45 | +``` |
| 46 | +$ async-kinesis list |
| 47 | +Name Status Shards |
| 48 | +----------- ------ ------ |
| 49 | +my-stream ACTIVE 2 |
| 50 | +events ACTIVE 4 |
| 51 | +``` |
| 52 | + |
| 53 | +### `describe` |
| 54 | + |
| 55 | +Show details about a specific stream including shard information. |
| 56 | + |
| 57 | +```bash |
| 58 | +async-kinesis describe STREAM |
| 59 | +``` |
| 60 | + |
| 61 | +**Example:** |
| 62 | +``` |
| 63 | +$ async-kinesis describe my-stream |
| 64 | + Name my-stream |
| 65 | + ARN arn:aws:kinesis:ap-southeast-2:123456789:stream/my-stream |
| 66 | + Status ACTIVE |
| 67 | + Retention 24 hours |
| 68 | + Encryption NONE |
| 69 | + Shards 1 |
| 70 | +
|
| 71 | +Shard ID Status Start Hash End Hash Start Seq End Seq |
| 72 | +-------------------- ------ ---------- --------------------------------------- ---------- ------- |
| 73 | +shardId-000000000000 OPEN 0 340282366920938463463374607431768211455 49635... |
| 74 | +``` |
| 75 | + |
| 76 | +### `tail` |
| 77 | + |
| 78 | +Tail records from a stream. Uses a real Consumer with MemoryCheckPointer for stateless tailing. |
| 79 | + |
| 80 | +```bash |
| 81 | +async-kinesis tail STREAM [OPTIONS] |
| 82 | +``` |
| 83 | + |
| 84 | +| Option | Default | Description | |
| 85 | +| --- | --- | --- | |
| 86 | +| `-i, --iterator-type` | `LATEST` | Where to start: `LATEST`, `TRIM_HORIZON`, `AT_TIMESTAMP` | |
| 87 | +| `-f, --format` | `json-pretty` | Output format: `json-pretty`, `json`, `raw`, `raw-short` | |
| 88 | +| `-p, --processor` | `json` | Record processor: `json`, `string` | |
| 89 | +| `-n, --max-records` | *(unlimited)* | Stop after N records | |
| 90 | + |
| 91 | +**Output formats:** |
| 92 | + |
| 93 | +| Format | Description | |
| 94 | +| --- | --- | |
| 95 | +| `json-pretty` | Indented JSON (default) | |
| 96 | +| `json` | Compact single-line JSON (good for piping to `jq`) | |
| 97 | +| `raw` | Python `repr()` of the deserialized record | |
| 98 | +| `raw-short` | Python `repr()` truncated to 120 characters | |
| 99 | + |
| 100 | +**Examples:** |
| 101 | + |
| 102 | +```bash |
| 103 | +# Live tail (latest records, Ctrl+C to stop) |
| 104 | +async-kinesis tail my-stream |
| 105 | + |
| 106 | +# Read from beginning, stop after 10 |
| 107 | +async-kinesis tail my-stream -i TRIM_HORIZON -n 10 |
| 108 | + |
| 109 | +# Compact JSON for piping |
| 110 | +async-kinesis tail my-stream -i TRIM_HORIZON -f json -n 100 | jq '.user_id' |
| 111 | + |
| 112 | +# Read raw strings (for StringProcessor data) |
| 113 | +async-kinesis tail my-stream -p string -f raw -n 5 |
| 114 | +``` |
| 115 | + |
| 116 | +### `put` |
| 117 | + |
| 118 | +Put records into a stream. Uses a real Producer with full batching and flushing. |
| 119 | + |
| 120 | +```bash |
| 121 | +async-kinesis put STREAM [DATA] [OPTIONS] |
| 122 | +``` |
| 123 | + |
| 124 | +| Option | Default | Description | |
| 125 | +| --- | --- | --- | |
| 126 | +| `-k, --partition-key` | *(auto-generated)* | Explicit partition key | |
| 127 | +| `-p, --processor` | `json` | Record processor: `json`, `string` | |
| 128 | +| `--create` | off | Create the stream if it does not exist | |
| 129 | + |
| 130 | +**Input modes:** |
| 131 | +- **Argument**: `async-kinesis put my-stream '{"key": "value"}'` — single record |
| 132 | +- **Stdin**: `cat data.jsonl | async-kinesis put my-stream` — one record per line |
| 133 | + |
| 134 | +When reading from a TTY without a pipe, a hint is printed to stderr. |
| 135 | + |
| 136 | +**Examples:** |
| 137 | + |
| 138 | +```bash |
| 139 | +# Single JSON record |
| 140 | +async-kinesis put my-stream '{"event": "page_view", "url": "/home"}' |
| 141 | + |
| 142 | +# With partition key |
| 143 | +async-kinesis put my-stream '{"user": 123}' -k user-123 |
| 144 | + |
| 145 | +# Create stream if needed |
| 146 | +async-kinesis put --create new-stream '{"first": "record"}' |
| 147 | + |
| 148 | +# Pipe JSONL file |
| 149 | +cat events.jsonl | async-kinesis put my-stream |
| 150 | + |
| 151 | +# Generate records |
| 152 | +seq 5 | jq -c '{n: .}' | async-kinesis put my-stream |
| 153 | + |
| 154 | +# String processor (no JSON parsing) |
| 155 | +async-kinesis put my-stream "plain text message" -p string |
| 156 | +``` |
| 157 | + |
| 158 | +## LocalStack / Kinesalite Usage |
| 159 | + |
| 160 | +```bash |
| 161 | +export ENDPOINT_URL=http://localhost:4566 # LocalStack |
| 162 | +export AWS_DEFAULT_REGION=ap-southeast-2 |
| 163 | +export AWS_ACCESS_KEY_ID=test |
| 164 | +export AWS_SECRET_ACCESS_KEY=test |
| 165 | + |
| 166 | +async-kinesis list |
| 167 | +async-kinesis put --create test-stream '{"hello": "world"}' |
| 168 | +async-kinesis tail test-stream -i TRIM_HORIZON -n 1 |
| 169 | +``` |
| 170 | + |
| 171 | +Or pass the endpoint directly: |
| 172 | + |
| 173 | +```bash |
| 174 | +async-kinesis --endpoint-url http://localhost:4567 list |
| 175 | +``` |
0 commit comments