dynamodb-streams-client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -0
- data/bin/dynamodb-streams +6 -0
- data/dynamodb-streams-client.gemspec +2 -0
- data/lib/dynamodb/streams/client.rb +7 -2
- data/lib/dynamodb/streams/client/cli.rb +103 -0
- data/lib/dynamodb/streams/client/version.rb +1 -1
- metadata +33 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc0aa590a3b2c835e20cf06b6a5f3b05d8dcc63f
|
4
|
+
data.tar.gz: 6c726caf62c67d0616568029f1b3a421a5a74310
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f73c51247af46e2a1570af218b20759f9026cdc6ce4463795eb8bcf52c53def4e78d264f6c9d3d46373b6146708307da111b6e2fa7815302e1fa53c1203b4cd7
|
7
|
+
data.tar.gz: 9abc3e1ae742ead23924aaddf815cffe077243c15eb2816a1480c8218abeb2b17d7526cec0eaee99c1919e7d057239e498bb06e1aae3360d4679065a8ca0447a
|
data/README.md
CHANGED
@@ -21,6 +21,9 @@ Or install it yourself as:
|
|
21
21
|
## Usage
|
22
22
|
|
23
23
|
```ruby
|
24
|
+
require 'dynamodb/streams/client'
|
25
|
+
require 'pp'
|
26
|
+
|
24
27
|
client = DynamoDB::Streams::Client.new(
|
25
28
|
access_key_id: 'YOUR_ACCESS_KEY_ID',
|
26
29
|
secret_access_key: 'YOUR_SECRET_ACCESS_KEY',
|
@@ -34,3 +37,27 @@ pp client.query('ListStreams')
|
|
34
37
|
# "...",
|
35
38
|
# "..."]}
|
36
39
|
```
|
40
|
+
|
41
|
+
## CLI
|
42
|
+
|
43
|
+
```sh
|
44
|
+
$ dynamodb-streams
|
45
|
+
Commands:
|
46
|
+
dynamodb-streams describe_stream STREAM_ID # Returns information about a stream
|
47
|
+
dynamodb-streams get_records SHARD_ITERATOR # Retrieves the stream records
|
48
|
+
dynamodb-streams get_shard_iterator STREAM_ID SHARD_ID SHARD_ITERATOR_TYPE # Returns a shard iterator
|
49
|
+
dynamodb-streams help [COMMAND] # Describe available commands or one specific command
|
50
|
+
dynamodb-streams list_streams # Returns an array of stream IDs
|
51
|
+
|
52
|
+
Options:
|
53
|
+
-k, [--access-key=ACCESS-KEY]
|
54
|
+
-s, [--secret-key=SECRET-KEY]
|
55
|
+
-e, [--endpoint=ENDPOINT]
|
56
|
+
-r, [--region=REGION]
|
57
|
+
```
|
58
|
+
|
59
|
+
### Follow record
|
60
|
+
|
61
|
+
```sh
|
62
|
+
dynamodb-streams get_records xxxxxxxx-xxxx-... -f --limit 10
|
63
|
+
```
|
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
+
spec.add_dependency 'thor'
|
22
|
+
spec.add_dependency 'deep_merge'
|
21
23
|
spec.add_development_dependency 'bundler'
|
22
24
|
spec.add_development_dependency 'rake'
|
23
25
|
end
|
@@ -7,7 +7,10 @@ require 'stringio'
|
|
7
7
|
require 'zlib'
|
8
8
|
require 'uri'
|
9
9
|
|
10
|
+
require 'thor'
|
11
|
+
|
10
12
|
require 'dynamodb/streams/client/version'
|
13
|
+
require 'dynamodb/streams/client/cli'
|
11
14
|
|
12
15
|
class DynamoDB::Streams::Client
|
13
16
|
class Error < StandardError
|
@@ -110,10 +113,12 @@ class DynamoDB::Streams::Client
|
|
110
113
|
|
111
114
|
if res_code != 200 or __type
|
112
115
|
errmsg = if __type
|
116
|
+
res_data_msg = res_data['message'] || res_data['Message'] || __type
|
117
|
+
|
113
118
|
if @debug
|
114
|
-
"#{__type}: #{
|
119
|
+
"#{__type}: #{res_data_msg}"
|
115
120
|
else
|
116
|
-
"#{
|
121
|
+
"#{res_data_msg}"
|
117
122
|
end
|
118
123
|
else
|
119
124
|
"#{res_code} #{res_msg}"
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'deep_merge'
|
2
|
+
|
3
|
+
class DynamoDB::Streams::Client::CLI < Thor
|
4
|
+
ITOR_WAIT = 0.3
|
5
|
+
|
6
|
+
class_option 'access-key', :aliases => '-k'
|
7
|
+
class_option 'secret-key', :aliases => '-s'
|
8
|
+
class_option 'endpoint', :aliases => '-e'
|
9
|
+
class_option 'region', :aliases => '-r'
|
10
|
+
|
11
|
+
desc 'list_streams', 'Returns an array of stream IDs'
|
12
|
+
def list_streams
|
13
|
+
res_data = iterate('StreamId') do |rh|
|
14
|
+
client.query('ListStreams', rh)
|
15
|
+
end
|
16
|
+
|
17
|
+
puts JSON.pretty_generate(res_data)
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'describe_stream STREAM_ID', 'Returns information about a stream'
|
21
|
+
def describe_stream(stream_id)
|
22
|
+
req_hash = {'StreamId' => stream_id}
|
23
|
+
|
24
|
+
res_data = iterate('ShardId', req_hash) do |rh|
|
25
|
+
client.query('DescribeStream', rh)
|
26
|
+
end
|
27
|
+
|
28
|
+
puts JSON.pretty_generate(res_data)
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'get_shard_iterator STREAM_ID SHARD_ID SHARD_ITERATOR_TYPE', 'Returns a shard iterator'
|
32
|
+
option 'sequence-number'
|
33
|
+
def get_shard_iterator(stream_id, shard_id, shard_iterator_type)
|
34
|
+
req_hash = {
|
35
|
+
'StreamId' => stream_id,
|
36
|
+
'ShardId' => shard_id,
|
37
|
+
'ShardIteratorType' => shard_iterator_type.upcase,
|
38
|
+
}
|
39
|
+
|
40
|
+
if seq_num = options['sequence-number']
|
41
|
+
req_hash['SequenceNumber'] = seq_num
|
42
|
+
end
|
43
|
+
|
44
|
+
res_data = client.query('GetShardIterator', req_hash)
|
45
|
+
puts JSON.pretty_generate(res_data)
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'get_records SHARD_ITERATOR', 'Retrieves the stream records'
|
49
|
+
option 'limit', :type => :numeric
|
50
|
+
option 'follow', :aliases => '-f'
|
51
|
+
def get_records(shard_iterator)
|
52
|
+
req_hash = {'ShardIterator' => shard_iterator}
|
53
|
+
req_hash['Limit'] = options['limit'] if options['limit']
|
54
|
+
|
55
|
+
loop do
|
56
|
+
res_data = client.query('GetRecords', req_hash)
|
57
|
+
puts JSON.pretty_generate(res_data)
|
58
|
+
next_shard_iterator = res_data['NextShardIterator']
|
59
|
+
|
60
|
+
unless options['follow'] and next_shard_iterator
|
61
|
+
break
|
62
|
+
end
|
63
|
+
|
64
|
+
req_hash['ShardIterator'] = next_shard_iterator
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
no_commands do
|
69
|
+
def iterate(item, req_hash = {})
|
70
|
+
res_data = {}
|
71
|
+
|
72
|
+
list = proc do |last_evaluated|
|
73
|
+
req_hash["ExclusiveStart#{item}"] = last_evaluated if last_evaluated
|
74
|
+
resp = yield(req_hash)
|
75
|
+
res_data.deep_merge!(resp)
|
76
|
+
resp["LastEvaluated#{item}"]
|
77
|
+
end
|
78
|
+
|
79
|
+
le = nil
|
80
|
+
|
81
|
+
loop do
|
82
|
+
le = list.call(le)
|
83
|
+
break unless le
|
84
|
+
end
|
85
|
+
|
86
|
+
res_data.delete("LastEvaluated#{item}")
|
87
|
+
res_data
|
88
|
+
end
|
89
|
+
|
90
|
+
def client
|
91
|
+
return @client if @client
|
92
|
+
|
93
|
+
client_options = {
|
94
|
+
:access_key_id => options.fetch('access-key', ENV['AWS_ACCESS_KEY_ID']),
|
95
|
+
:secret_access_key => options.fetch('secret-key', ENV['AWS_SECRET_ACCESS_KEY']),
|
96
|
+
:endpoint => options.fetch('endpoint', ENV['DYNAMODB_STREAMS_ENDPOINT']),
|
97
|
+
:region => options['region'],
|
98
|
+
}
|
99
|
+
|
100
|
+
@client = DynamoDB::Streams::Client.new(client_options)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamodb-streams-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
@@ -10,6 +10,34 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: deep_merge
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -41,7 +69,8 @@ dependencies:
|
|
41
69
|
description: DynamoDB Streams client.
|
42
70
|
email:
|
43
71
|
- sgwr_dts@yahoo.co.jp
|
44
|
-
executables:
|
72
|
+
executables:
|
73
|
+
- dynamodb-streams
|
45
74
|
extensions: []
|
46
75
|
extra_rdoc_files: []
|
47
76
|
files:
|
@@ -50,8 +79,10 @@ files:
|
|
50
79
|
- LICENSE.txt
|
51
80
|
- README.md
|
52
81
|
- Rakefile
|
82
|
+
- bin/dynamodb-streams
|
53
83
|
- dynamodb-streams-client.gemspec
|
54
84
|
- lib/dynamodb/streams/client.rb
|
85
|
+
- lib/dynamodb/streams/client/cli.rb
|
55
86
|
- lib/dynamodb/streams/client/version.rb
|
56
87
|
homepage: https://github.com/winebarrel/dynamodb-streams-client
|
57
88
|
licenses:
|