Skip to content

Commit 2c6807b

Browse files
committed
Merge branch 'kinesis_cli' of https://github.com/cameront/go-kinesis
2 parents 9a46758 + 60980ff commit 2c6807b

File tree

6 files changed

+412
-3
lines changed

6 files changed

+412
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ _cgo_export.*
2020
_testmain.go
2121

2222
*.exe
23+
24+
kinesis-cli/kinesis-cli

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ GO-lang library for AWS Kinesis API.
88
## Example
99

1010
Example you can find in folder `examples`.
11+
12+
## Command line interface
13+
14+
You can find a tool for interacting with kinesis from the command line in folder `kinesis-cli`.

client.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import (
55
"os"
66
)
77

8+
const (
9+
ACCESS_ENV_KEY = "AWS_ACCESS_KEY"
10+
SECRET_ENV_KEY = "AWS_SECRET_KEY"
11+
)
12+
813
// Auth store information about AWS Credentials
914
type Auth struct {
1015
AccessKey, SecretKey, Token string
@@ -20,10 +25,10 @@ type Client struct {
2025
// New creates a new Client.
2126
func NewClient(auth *Auth) *Client {
2227
if auth.AccessKey == "" {
23-
auth.AccessKey = os.Getenv("AWS_ACCESS_KEY")
28+
auth.AccessKey = os.Getenv(ACCESS_ENV_KEY)
2429
}
2530
if auth.SecretKey == "" {
26-
auth.SecretKey = os.Getenv("AWS_SECRET_KEY")
31+
auth.SecretKey = os.Getenv(SECRET_ENV_KEY)
2732
}
2833
return &Client{Auth: auth}
2934
}

kinesis-cli/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# kinesis-cli
2+
3+
kinesis-cli is a tool for interacting with kinesis from the command line.
4+
5+
## Setup
6+
7+
You can either install the kinesis-cli using `go get` or `go install`:
8+
(TODO: verify this works)
9+
10+
$ go install github.com/sendgridlabs/go-kinesis/kinesis-cli
11+
12+
or build it and run it from the kinesis-cli folder:
13+
14+
```
15+
$ go get github.com/sendgridlabs/go-kinesis/kinesis-cli
16+
$ cd $GOPATH/src/github.com/sendgridlabs/go-kinesis/kinesis-cli
17+
$ go build
18+
$ ./kinesis-cli
19+
Usage: ./kinesis-cli <command> [<arg>, ...]
20+
(Note: expects $AWS_ACCESS_KEY and $AWS_SECRET_KEY to be set)
21+
Commands:
22+
create <streamName> [<numShards>]
23+
delete <streamName>
24+
describe <streamName> [<startShardId> <limit>]
25+
split <streamName> <shardId> [<hash>]
26+
merge <streamName> <shardId> <adjacentShardId>
27+
```
28+
29+
Note that you'll need to store your access/secret key in the proper env vars:
30+
31+
$ export AWS_ACCESS_KEY=123myaccesskey456; export AWS_SECRET_KEY=789myVerySecretKey432
32+
33+
## Usage
34+
35+
For all commands except `describe`, you will be prompted for confirmation before the aws request is sent.
36+
37+
##### Create a new stream: (only a single shard is created if num shards is not specified)
38+
39+
$ ./kinesis-cli create somestream 2
40+
41+
##### Delete an existing stream:
42+
43+
$ ./kinesis-cli delete somestream
44+
45+
##### Describe a stream:
46+
47+
```
48+
$ ./kinesis-cli describe somestream
49+
{
50+
"StreamDescription": {
51+
"HasMoreShards": false,
52+
"Shards": [
53+
{
54+
"AdjacentParentShardId": "",
55+
"HashKeyRange": {
56+
"EndingHashKey": "170141183460469231731687303715884105727",
57+
"StartingHashKey": "0"
58+
},
59+
"ParentShardId": "",
60+
"SequenceNumberRange": {
61+
"EndingSequenceNumber": "",
62+
"StartingSequenceNumber": "49540491727041816751370913972624375777284624614827229185"
63+
},
64+
"ShardId": "shardId-000000000000"
65+
},
66+
{
67+
"AdjacentParentShardId": "",
68+
"HashKeyRange": {
69+
"EndingHashKey": "340282366920938463463374607431768211455",
70+
"StartingHashKey": "170141183460469231731687303715884105728"
71+
},
72+
"ParentShardId": "",
73+
"SequenceNumberRange": {
74+
"EndingSequenceNumber": "",
75+
"StartingSequenceNumber": "49540491727064117496569444595765911495557272976333209617"
76+
},
77+
"ShardId": "shardId-000000000001"
78+
}
79+
],
80+
"StreamARN": "arn:aws:kinesis:us-east-1:123456789:stream/somestream",
81+
"StreamName": "somestream",
82+
"StreamStatus": "ACTIVE"
83+
}
84+
}
85+
86+
```
87+
88+
##### Split a shard: (it will suggest a new hash key that evenly splits the shard)
89+
90+
```
91+
$ ./kinesis-cli split somestream shardId-000000000000
92+
Shard's current hash key range (0 - 170141183460469231731687303715884105727)
93+
Default (even split) key: 85070591730234615865843651857942052863
94+
Type new key or press [enter] to choose default:
95+
Are you sure you want to split shard shardId-000000000000 at hash key 85070591730234615865843651857942052863?
96+
(y/N): y
97+
```
98+
99+
##### Merge two adjacent shards: (must be specified in low->high order)
100+
101+
$ go build && ./kinesis-cli merge somestream shardId-000000000003 shardId-000000000001

0 commit comments

Comments
 (0)