aws-sdk 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -124,7 +124,7 @@ module AWS
124
124
  provider.provides *template_attributes.keys
125
125
  end
126
126
 
127
- # @retun [Array<StackOutput>]
127
+ # @return [Array<StackOutput>]
128
128
  def outputs
129
129
  output_details.collect do |o|
130
130
  StackOutput.new(self, o.output_key, o.output_value, o.description)
@@ -61,7 +61,7 @@ require 'aws/core/autoloader'
61
61
  module AWS
62
62
 
63
63
  # Current version of the AWS SDK for Ruby
64
- VERSION = "1.4.0"
64
+ VERSION = "1.4.1"
65
65
 
66
66
  register_autoloads(self) do
67
67
  autoload :Errors, 'errors'
@@ -113,6 +113,7 @@ module AWS
113
113
  AWS.register_autoloads(self, 'aws/dynamo_db') do
114
114
  autoload :AttributeCollection, 'attribute_collection'
115
115
  autoload :BatchGet, 'batch_get'
116
+ autoload :BatchWrite, 'batch_write'
116
117
  autoload :Client, 'client'
117
118
  autoload :Errors, 'errors'
118
119
  autoload :Expectations, 'expectations'
@@ -169,5 +170,44 @@ module AWS
169
170
  batch.enumerator
170
171
  end
171
172
 
173
+ # Yields a batch for writing (put and delete) items across multiple
174
+ # tables. You can put and delete items in the same batch.
175
+ #
176
+ # @example Putting items across tables
177
+ #
178
+ # # shard data across two tables with batch write
179
+ # items = [
180
+ # { :id => '123', :color => 'red' },
181
+ # { :id => '456', :color => 'blue' },
182
+ # { :id => '789', :color => 'green' },
183
+ # ]
184
+ #
185
+ # ddb.batch_write do |batch|
186
+ # batch.put('table1', items)
187
+ # batch.put('table2', items)
188
+ # end
189
+ #
190
+ # @example Mixing puts and deletes
191
+ #
192
+ # ddb.batch_write do |batch|
193
+ # batch.write('table1', :put => [...], :delete => [...])
194
+ # batch.write('table2', :put => [...], :delete => [...])
195
+ # end
196
+ #
197
+ # @yield [BatchWrite]
198
+ #
199
+ # @return (see BatchWrite#process!)
200
+ #
201
+ # @see BatchWrite
202
+ # @see BatchWrite#put
203
+ # @see BatchWrite#delete
204
+ # @see BatchWrite#write
205
+ #
206
+ def batch_write &block
207
+ batch = BatchWrite.new(:config => config)
208
+ yield(batch)
209
+ batch.process!
210
+ end
211
+
172
212
  end
173
213
  end
@@ -0,0 +1,251 @@
1
+ # Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+
14
+ module AWS
15
+ class DynamoDB
16
+ class BatchWrite
17
+
18
+ include Types
19
+ include Core::Model
20
+
21
+ def initialize options = {}
22
+ super(options)
23
+ @request_items = {}
24
+ end
25
+
26
+ # Adds one or more items to the batch write operation.
27
+ #
28
+ # # adding one item at a time to the batch
29
+ # batch = AWS::DynamoDB::BatchWrite.new
30
+ # batch.put('table-name', :id => 'id1', :color => 'red')
31
+ # batch.put('table-name', :id => 'id2', :color => 'blue')
32
+ # batch.process!
33
+ #
34
+ # # adding multiple items to a batch
35
+ # batch = AWS::DynamoDB::BatchWrite.new
36
+ # batch.put('table-name', [
37
+ # { :id => 'id1', :color => 'red' },
38
+ # { :id => 'id2', :color => 'blue' },
39
+ # { :id => 'id3', :color => 'green' },
40
+ # ])
41
+ # batch.process!
42
+ #
43
+ # @param [Table,String] table A {Table} object or table name string.
44
+ #
45
+ # @param [Array<Hash>] items A list of item attributes to put.
46
+ # The hash must contain the table hash key element and range key
47
+ # element (if one is defined).
48
+ #
49
+ # @return [nil]
50
+ #
51
+ def put table, items
52
+ write(table, :put => items.flatten)
53
+ nil
54
+ end
55
+
56
+ # Adds one or more items to the batch to delete.
57
+ #
58
+ # # for a table w/out a range key
59
+ # batch = AWS::DynamoDB::BatchWrite.new
60
+ # batch.delete('table-name', %w(hk1 hk2))
61
+ # batch.process!
62
+ #
63
+ # # for a table with a range key
64
+ # batch = AWS::DynamoDB::BatchWrite.new
65
+ # batch.delete('table-name', [['hk1', 'rk2'], ['hk1', 'rk2']]])
66
+ # batch.process!
67
+ #
68
+ # @param [Table,String] table A {Table} object or table name string.
69
+ #
70
+ # @param [Array<String>,Array<Array>] items A list of item keys to
71
+ # delete. For tables without a range key, items should be an array
72
+ # of hash key strings.
73
+ #
74
+ # batch.delete('table-name', ['hk1', 'hk2', 'hk3'])
75
+ #
76
+ # For tables with a range key, items should be an array of
77
+ # hash key and range key pairs.
78
+ #
79
+ # batch.delete('table-name', [['hk1', 'rk1'], ['hk1', 'rk2']])
80
+ #
81
+ # @return [nil]
82
+ #
83
+ def delete table, items
84
+ write(table, :delete => items)
85
+ nil
86
+ end
87
+
88
+ # Add items to the batch. Accepts both item to put and and items
89
+ # to delete.
90
+ #
91
+ # @param [Table,String] table A {Table} object or table name string.
92
+ #
93
+ # @param [Hash] options
94
+ #
95
+ # @option options [Array<Hash>] :put An array of items to put. Each item
96
+ # should be an array of attribute hashes.
97
+ #
98
+ # # add 3 items to the batch
99
+ # batch.write(table, :put => [
100
+ # { :id => 'abc', :color => 'red', :count => 2 },
101
+ # { :id => 'mno', :color => 'blue', :count => 3 },
102
+ # { :id => 'xyz', :color => 'green', :count => 5 },
103
+ # ])
104
+ #
105
+ # @option options [Array<String>,Array<Array>] :delete A list of item keys
106
+ # to delete. For tables without a range key, items should be an array
107
+ # of hash key strings.
108
+ #
109
+ # batch.write('table-name', :delete => ['hk1', 'hk2', 'hk3'])
110
+ #
111
+ # For tables with a range key, items should be an array of
112
+ # hash key and range key pairs.
113
+ #
114
+ # batch.write('table-name', :delete => [['hk1', 'rk1'], ['hk1', 'rk2']])
115
+ #
116
+ def write table, options = {}
117
+
118
+ items = table_items(table)
119
+
120
+ if put = options[:put]
121
+ put.each do |attributes|
122
+ items << { :put_request => { :item => format_put(attributes) }}
123
+ end
124
+ end
125
+
126
+ if del = options[:delete]
127
+ del.each do |keys|
128
+ items << { :delete_request => { :key => format_delete(keys) }}
129
+ end
130
+ end
131
+
132
+ end
133
+
134
+ # Proccesses pending request items.
135
+ # @return [nil]
136
+ def process!
137
+
138
+ return if @request_items.empty?
139
+
140
+ opts = { :request_items => @request_items }
141
+
142
+ begin
143
+
144
+ response = client.batch_write_item(opts)
145
+
146
+ unprocessed = response.data['UnprocessedItems']
147
+
148
+ opts[:request_items] = convert_unprocessed_items(unprocessed)
149
+
150
+ end while opts[:request_items]
151
+
152
+ @request_items = {}
153
+ nil
154
+
155
+ end
156
+
157
+ protected
158
+
159
+ def table_name table
160
+ table.is_a?(Table) ? table.name : table.to_s
161
+ end
162
+
163
+ def table_items table
164
+ @request_items[table_name(table)] ||= []
165
+ end
166
+
167
+ def format_put attributes
168
+ attributes.inject({}) do |hash, (key, value)|
169
+ context = "value for attribute #{key}"
170
+ hash.merge(key.to_s => format_attribute_value(value, context))
171
+ end
172
+ end
173
+
174
+ def format_delete keys
175
+
176
+ keys = [keys] unless keys.is_a?(Array)
177
+
178
+ item = {}
179
+ item[:hash_key_element] = format_attribute_value(keys.first)
180
+ item[:range_key_element] = format_attribute_value(keys.last) if
181
+ keys.count > 1
182
+
183
+ item
184
+
185
+ end
186
+
187
+ def convert_unprocessed_items items
188
+
189
+ return nil if items.empty?
190
+
191
+ request_items = {}
192
+
193
+ items.each_pair do |table,requests|
194
+
195
+ request_items[table] ||= []
196
+
197
+ requests.each do |request|
198
+
199
+ item = request.values.first
200
+
201
+ request_items[table] <<
202
+ case request.keys.first
203
+ when 'PutRequest' then convert_put_item(item['Item'])
204
+ when 'DeleteRequest' then convert_delete_item(item['Key'])
205
+ end
206
+
207
+ end
208
+
209
+ end
210
+
211
+ request_items
212
+
213
+ end
214
+
215
+ def convert_put_item item
216
+
217
+ attributes = {}
218
+ item.each_pair do |name,value|
219
+ attributes[name] = str2sym(value)
220
+ end
221
+
222
+ { :put_request => { :item => attributes }}
223
+
224
+ end
225
+
226
+ def convert_delete_item item
227
+
228
+ key = {}
229
+ key[:hash_key_element] = str2sym(item['HashKeyElement'])
230
+ key[:range_key_element] = str2sym(item['RangeKeyElement']) if
231
+ item['RangeKeyElement']
232
+
233
+ { :delete_request => { :key => key}}
234
+
235
+ end
236
+
237
+ def str2sym key_desc
238
+ type, value = key_desc.to_a.flatten
239
+ case type
240
+ when "S" then { :s => value }
241
+ when "N" then { :n => value }
242
+ when "SS" then { :ss => value }
243
+ when "NS" then { :ns => value }
244
+ else
245
+ raise "unhandled key type: #{type.inspect}"
246
+ end
247
+ end
248
+
249
+ end
250
+ end
251
+ end
@@ -402,6 +402,96 @@ module AWS
402
402
  block_given? ? enum.each(&block) : enum
403
403
  end
404
404
 
405
+ # Batch puts up to 25 items to this table.
406
+ #
407
+ # table.batch_put([
408
+ # { :id => 'id1', :color => 'red' },
409
+ # { :id => 'id2', :color => 'blue' },
410
+ # { :id => 'id3', :color => 'green' },
411
+ # ])
412
+ #
413
+ # @param [Array<Hash>] items A list of item attributes to put.
414
+ # The hash must contain the table hash key element and range key
415
+ # element (if one is defined).
416
+ #
417
+ # @return (see BatchWrite#process!)
418
+ #
419
+ def batch_put items
420
+ batch = BatchWrite.new(:config => config)
421
+ batch.put(self, options)
422
+ batch.process!
423
+ end
424
+
425
+ # Batch delets up to 25 items.
426
+ #
427
+ # table.batch_delete(%w(id1 id2 id3 id4))
428
+ #
429
+ # @param [Array<String>,Array<Array>] items A list of item keys to
430
+ # delete. For tables without a range key, items should be an array
431
+ # of hash key strings.
432
+ #
433
+ # batch.delete('table-name', ['hk1', 'hk2', 'hk3'])
434
+ #
435
+ # For tables with a range key, items should be an array of
436
+ # hash key and range key pairs.
437
+ #
438
+ # batch.delete('table-name', [['hk1', 'rk1'], ['hk1', 'rk2']])
439
+ #
440
+ # @return (see BatchWrite#process!)
441
+ #
442
+ def batch_put items
443
+ batch = BatchWrite.new(:config => config)
444
+ batch.put(self, items)
445
+ batch.process!
446
+ end
447
+
448
+ # Batch writes up to 25 items to this table. A batch may contain
449
+ # a mix of items to put and items to delete.
450
+ #
451
+ # table.batch_write(
452
+ # :put => [
453
+ # { :id => 'id1', :color => 'red' },
454
+ # { :id => 'id2', :color => 'blue' },
455
+ # { :id => 'id3', :color => 'green' },
456
+ # ],
457
+ # :delete => ['id4', 'id5']
458
+ # )
459
+ #
460
+ # @param [Hash] options
461
+ #
462
+ # @option options (BatchWrite#write)
463
+ #
464
+ # @return (see BatchWrite#process!)
465
+ #
466
+ def batch_write options = {}
467
+ batch = BatchWrite.new(:config => config)
468
+ batch.write(self, options)
469
+ batch.process!
470
+ end
471
+
472
+ # Delete up to 25 items in a single batch.
473
+ #
474
+ # table.batch_delete(%w(id1 id2 id3 id4 id5))
475
+ #
476
+ # @param [Array<String>,Array<Array>] items A list of item keys to
477
+ # delete. For tables without a range key, items should be an array
478
+ # of hash key strings.
479
+ #
480
+ # batch.delete('table-name', ['hk1', 'hk2', 'hk3'])
481
+ #
482
+ # For tables with a range key, items should be an array of
483
+ # hash key and range key pairs.
484
+ #
485
+ # batch.delete('table-name', [['hk1', 'rk1'], ['hk1', 'rk2']])
486
+ #
487
+ # @return (see BatchWrite#process!)
488
+ #
489
+ def batch_delete items
490
+ batch = BatchWrite.new(:config => config)
491
+ batch.delete(self, items)
492
+ batch.process!
493
+ end
494
+
405
495
  protected
406
496
  def get_resource attribute_name = nil
407
497
  client.describe_table(resource_options)
@@ -17,8 +17,8 @@ module AWS
17
17
 
18
18
  # @param [Hash] options
19
19
  #
20
- # @option [Boolean] :vpc (false) When true, the elastic ip address
21
- # will be allocated to your VPC.
20
+ # @option options [Boolean] :vpc (false) When true, the elastic ip
21
+ # address will be allocated to your VPC.
22
22
  #
23
23
  # @return [ElasticIp]
24
24
  #
@@ -33,9 +33,8 @@ module AWS
33
33
  # @option options [Boolean] :instance_tenancy (:default)
34
34
  # The allowed tenancy of instances launched into the VPC. A value of
35
35
  # +:default+ means instances can be launched with any tenancy; a value
36
- # of +:dedicated+ means instances must be launched with tenancy as
37
- # dedicated.
38
- # dedicated tenancy.
36
+ # of +:dedicated+ means all instances launched into the VPC will be launched with
37
+ # dedicated tenancy regardless of the tenancy assigned to the instance at launch.
39
38
  #
40
39
  # @return [VPC]
41
40
  #
metadata CHANGED
@@ -1,92 +1,86 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: aws-sdk
3
- version: !ruby/object:Gem::Version
4
- hash: 7
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.1
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 4
9
- - 0
10
- version: 1.4.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Amazon Web Services
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-04-12 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- version_requirements: &id001 !ruby/object:Gem::Requirement
12
+ date: 2012-04-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: uuidtools
16
+ requirement: !ruby/object:Gem::Requirement
22
17
  none: false
23
- requirements:
18
+ requirements:
24
19
  - - ~>
25
- - !ruby/object:Gem::Version
26
- hash: 1
27
- segments:
28
- - 2
29
- - 1
30
- version: "2.1"
31
- name: uuidtools
20
+ - !ruby/object:Gem::Version
21
+ version: '2.1'
32
22
  type: :runtime
33
23
  prerelease: false
34
- requirement: *id001
35
- - !ruby/object:Gem::Dependency
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
37
25
  none: false
38
- requirements:
26
+ requirements:
39
27
  - - ~>
40
- - !ruby/object:Gem::Version
41
- hash: 5
42
- segments:
43
- - 0
44
- - 7
45
- version: "0.7"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.1'
30
+ - !ruby/object:Gem::Dependency
46
31
  name: httparty
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.7'
47
38
  type: :runtime
48
39
  prerelease: false
49
- requirement: *id002
50
- - !ruby/object:Gem::Dependency
51
- version_requirements: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
52
41
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 15
57
- segments:
58
- - 1
59
- - 4
60
- - 4
61
- version: 1.4.4
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.7'
46
+ - !ruby/object:Gem::Dependency
62
47
  name: nokogiri
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.4.4
63
54
  type: :runtime
64
55
  prerelease: false
65
- requirement: *id003
66
- - !ruby/object:Gem::Dependency
67
- version_requirements: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
68
57
  none: false
69
- requirements:
70
- - - ~>
71
- - !ruby/object:Gem::Version
72
- hash: 7
73
- segments:
74
- - 1
75
- - 4
76
- version: "1.4"
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.4.4
62
+ - !ruby/object:Gem::Dependency
77
63
  name: json
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.4'
78
70
  type: :runtime
79
71
  prerelease: false
80
- requirement: *id004
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.4'
81
78
  description: AWS SDK for Ruby
82
79
  email:
83
80
  executables: []
84
-
85
81
  extensions: []
86
-
87
82
  extra_rdoc_files: []
88
-
89
- files:
83
+ files:
90
84
  - ca-bundle.crt
91
85
  - rails/init.rb
92
86
  - lib/aws/auto_scaling/activity.rb
@@ -178,6 +172,7 @@ files:
178
172
  - lib/aws/core.rb
179
173
  - lib/aws/dynamo_db/attribute_collection.rb
180
174
  - lib/aws/dynamo_db/batch_get.rb
175
+ - lib/aws/dynamo_db/batch_write.rb
181
176
  - lib/aws/dynamo_db/client.rb
182
177
  - lib/aws/dynamo_db/config.rb
183
178
  - lib/aws/dynamo_db/errors.rb
@@ -487,37 +482,31 @@ files:
487
482
  - NOTICE.txt
488
483
  - LICENSE.txt
489
484
  homepage: http://aws.amazon.com/sdkforruby
490
- licenses:
485
+ licenses:
491
486
  - Apache 2.0
492
487
  post_install_message:
493
488
  rdoc_options: []
494
-
495
- require_paths:
489
+ require_paths:
496
490
  - lib
497
- required_ruby_version: !ruby/object:Gem::Requirement
491
+ required_ruby_version: !ruby/object:Gem::Requirement
498
492
  none: false
499
- requirements:
500
- - - ">="
501
- - !ruby/object:Gem::Version
502
- hash: 3
503
- segments:
493
+ requirements:
494
+ - - ! '>='
495
+ - !ruby/object:Gem::Version
496
+ version: '0'
497
+ segments:
504
498
  - 0
505
- version: "0"
506
- required_rubygems_version: !ruby/object:Gem::Requirement
499
+ hash: 886230137059201469
500
+ required_rubygems_version: !ruby/object:Gem::Requirement
507
501
  none: false
508
- requirements:
509
- - - ">="
510
- - !ruby/object:Gem::Version
511
- hash: 3
512
- segments:
513
- - 0
514
- version: "0"
502
+ requirements:
503
+ - - ! '>='
504
+ - !ruby/object:Gem::Version
505
+ version: '0'
515
506
  requirements: []
516
-
517
507
  rubyforge_project:
518
508
  rubygems_version: 1.8.21
519
509
  signing_key:
520
510
  specification_version: 3
521
511
  summary: AWS SDK for Ruby
522
512
  test_files: []
523
-