aws-sdk-dynamodb 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ # utility classes
2
+ require 'aws-sdk-dynamodb/attribute_value'
3
+
4
+ # customizations to generated classes
5
+ require 'aws-sdk-dynamodb/customizations/client'
@@ -0,0 +1,31 @@
1
+ module Aws
2
+ module DynamoDB
3
+ class Client
4
+
5
+ def stub_data(operation_name, data = {})
6
+ if config.simple_attributes
7
+ rules = config.api.operation(operation_name).output
8
+ translator = Plugins::SimpleAttributes::ValueTranslator
9
+ data = translator.apply(rules, :marshal, data)
10
+ data = super(operation_name, data)
11
+ translator.apply(rules, :unmarshal, data)
12
+ else
13
+ super
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def data_to_http_resp(operation_name, data)
20
+ api = config.api
21
+ operation = api.operation(operation_name)
22
+ translator = Plugins::SimpleAttributes::ValueTranslator
23
+ translator = translator.new(operation.output, :marshal)
24
+ data = translator.apply(data)
25
+ ParamValidator.validate!(operation.output, data)
26
+ protocol_helper.stub_data(api, operation, data)
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ # WARNING ABOUT GENERATED CODE
2
+ #
3
+ # This file is generated. See the contributing for info on making contributions:
4
+ # https://github.com/aws/aws-sdk-ruby/blob/master/CONTRIBUTING.md
5
+ #
6
+ # WARNING ABOUT GENERATED CODE
7
+
8
+ module Aws
9
+ module DynamoDB
10
+ module Errors
11
+
12
+ extend Aws::Errors::DynamicErrors
13
+
14
+ # Raised when calling #load or #data on a resource class that can not be
15
+ # loaded. This can happen when:
16
+ #
17
+ # * A resource class has identifiers, but no data attributes.
18
+ # * Resource data is only available when making an API call that
19
+ # enumerates all resources of that type.
20
+ class ResourceNotLoadable < RuntimeError; end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,56 @@
1
+ module Aws
2
+ module DynamoDB
3
+ module Plugins
4
+ class CRC32Validation < Seahorse::Client::Plugin
5
+
6
+ option(:compute_checksums,
7
+ default: true,
8
+ doc_type: 'Boolean',
9
+ docstring: <<-DOCS)
10
+ When `true`, a CRC32 checksum is computed of every HTTP
11
+ response body and compared against the `X-Amz-Crc32` header.
12
+ If the checksums do not match, the request is re-sent.
13
+ Failures can be retried up to `:retry_limit` times.
14
+ DOCS
15
+
16
+ def add_handlers(handlers, config)
17
+ if config.compute_checksums
18
+ handlers.add(Handler, step: :sign)
19
+ end
20
+ end
21
+
22
+ class Handler < Seahorse::Client::Handler
23
+
24
+ def call(context)
25
+ # disable response gzipping - Net::HTTP unzips these responses
26
+ # before we can see the body, making it impossible to verify
27
+ # the CRC32 checksum against the compressed body stream
28
+ context.http_request.headers['accept-encoding'] = ''
29
+
30
+ @handler.call(context).on_success do |response|
31
+ response.error = validate(context)
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def validate(context)
38
+ unless crc32_is_valid?(context.http_response)
39
+ msg = "Response failed CRC32 check."
40
+ return Errors::CRC32CheckFailed.new(context, msg)
41
+ end
42
+ end
43
+
44
+ def crc32_is_valid?(response)
45
+ if crc_checksum = response.headers['x-amz-crc32']
46
+ crc_checksum.to_i == Zlib.crc32(response.body_contents)
47
+ else
48
+ true
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,27 @@
1
+ module Aws
2
+ module DynamoDB
3
+ module Plugins
4
+ class ExtendedRetries < Seahorse::Client::Plugin
5
+
6
+ option(:retry_limit,
7
+ default: 10,
8
+ required: false,
9
+ doc_type: Integer,
10
+ docstring: <<-DOCS)
11
+ The maximum number of times to retry failed requests. Only
12
+ ~ 500 level server errors and certain ~ 400 level client errors
13
+ are retried. Generally, these are throttling errors, data
14
+ checksum errors, networking errors, timeout errors and auth
15
+ errors from expired credentials.
16
+ DOCS
17
+
18
+ option(:retry_backoff, default: lambda { |context|
19
+ if context.retries > 1
20
+ Kernel.sleep(50 * (2 ** (context.retries - 1)) / 1000.0)
21
+ end
22
+ })
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,215 @@
1
+ module Aws
2
+ module DynamoDB
3
+ module Plugins
4
+ # Simplifies working with Amazon DynamoDB attribute values.
5
+ # Translates attribute values for requests and responses to sensible
6
+ # Ruby natives.
7
+ #
8
+ # This plugin is enabled by default for all {DynamoDB::Client}
9
+ # objects. You can disable this plugin by passing
10
+ # `simple_attributes: false` to the client constructor:
11
+ #
12
+ # ddb = Aws::DynamoDB::Client.new(simple_attributes: false)
13
+ #
14
+ # ## Input Examples
15
+ #
16
+ # With this plugin **enabled**, `simple_attributes: true`:
17
+ #
18
+ # dynamodb.put_item(
19
+ # table_name: 'aws-sdk',
20
+ # item: {
21
+ # id: 'uuid',
22
+ # age: 35,
23
+ # tags: Set.new(%w(simple attributes)),
24
+ # data: StringIO.new('data'),
25
+ # scores: [5, 4.5, 4.9, nil],
26
+ # name: {
27
+ # first: 'John',
28
+ # last: 'Doe',
29
+ # }
30
+ # }
31
+ # )
32
+ #
33
+ # With this plugin **disabled**, `simple_attributes: false`:
34
+ #
35
+ # # note that all types are prefixed in a hash and that
36
+ # # numeric types must be serialized as strings
37
+ # dynamodb.put_item(
38
+ # table_name: 'aws-sdk',
39
+ # item: {
40
+ # 'id' => { s: 'uuid' },
41
+ # 'age' => { n: '35' },
42
+ # 'tags' => { ss: ['simple', 'attributes'] },
43
+ # 'data' => { b: 'data' },
44
+ # 'scores' => {
45
+ # l: [
46
+ # { n: '5' },
47
+ # { n: '4.5' },
48
+ # { n: '4.9' },
49
+ # { null: true },
50
+ # ]
51
+ # },
52
+ # 'name' => {
53
+ # m: {
54
+ # 'first' => { s: 'John' },
55
+ # 'last' => { s: 'Doe' },
56
+ # }
57
+ # }
58
+ # }
59
+ # )
60
+ #
61
+ # ## Output Examples
62
+ #
63
+ # With this plugin **enabled**, `simple_attributes: true`:
64
+ #
65
+ # resp = dynamodb.get(table_name: 'aws-sdk', key: { id: 'uuid' })
66
+ # resp.item
67
+ # {
68
+ # id: 'uuid',
69
+ # age: 35,
70
+ # tags: Set.new(%w(simple attributes)),
71
+ # data: StringIO.new('data'),
72
+ # scores: [5, 4.5, 4.9, nil],
73
+ # name: {
74
+ # first: 'John',
75
+ # last: 'Doe',
76
+ # }
77
+ # }
78
+ #
79
+ # With this plugin **disabled**, `simple_attributes: false`:
80
+ #
81
+ # # note that the request `:key` had to be type prefixed
82
+ # resp = dynamodb.get(table_name: 'aws-sdk', key: { 'id' => { s: 'uuid' }})
83
+ # resp.item
84
+ # # {
85
+ # # "id"=> <struct s='uuid', n=nil, b=nil, ss=nil, ns=nil, bs=nil, m=nil, l=nil, null=nil, bool=nil>
86
+ # # "age"=> <struct s=nil, n="35", b=nil, ss=nil, ns=nil, bs=nil, m=nil, l=nil, null=nil, bool=nil>
87
+ # # ...
88
+ # # }
89
+ #
90
+ class SimpleAttributes < Seahorse::Client::Plugin
91
+
92
+ option(:simple_attributes,
93
+ doc_default: true,
94
+ doc_type: 'Boolean',
95
+ docstring: <<-DOCS
96
+ Enables working with DynamoDB attribute values using
97
+ hashes, arrays, sets, integers, floats, booleans, and nil.
98
+
99
+ Disabling this option requires that all attribute values have
100
+ their types specified, e.g. `{ s: 'abc' }` instead of simply
101
+ `'abc'`.
102
+ DOCS
103
+ ) do |config|
104
+ !config.simple_json
105
+ end
106
+
107
+ def add_handlers(handlers, config)
108
+ if config.simple_attributes
109
+ handlers.add(Handler, step: :initialize)
110
+ end
111
+ end
112
+
113
+ class Handler < Seahorse::Client::Handler
114
+
115
+ def call(context)
116
+ context.params = translate_input(context)
117
+ @handler.call(context).on(200) do |response|
118
+ response.data = translate_output(response)
119
+ end
120
+ end
121
+
122
+ private
123
+
124
+ def translate_input(context)
125
+ if shape = context.operation.input
126
+ ValueTranslator.new(shape, :marshal).apply(context.params)
127
+ else
128
+ context.params
129
+ end
130
+ end
131
+
132
+ def translate_output(response)
133
+ if shape = response.context.operation.output
134
+ ValueTranslator.new(shape, :unmarshal).apply(response.data)
135
+ else
136
+ response.data
137
+ end
138
+ end
139
+
140
+ end
141
+
142
+ # @api private
143
+ class ValueTranslator
144
+
145
+ include Seahorse::Model::Shapes
146
+
147
+ def self.apply(rules, mode, data)
148
+ new(rules, mode).apply(data)
149
+ end
150
+
151
+ def initialize(rules, mode)
152
+ @rules = rules
153
+ @mode = mode
154
+ end
155
+
156
+ def apply(values)
157
+ structure(@rules, values) if @rules
158
+ end
159
+
160
+ private
161
+
162
+ def structure(ref, values)
163
+ shape = ref.shape
164
+ if values.is_a?(Struct)
165
+ values.members.each do |key|
166
+ values[key] = translate(shape.member(key), values[key])
167
+ end
168
+ values
169
+ elsif values.is_a?(Hash)
170
+ values.each.with_object({}) do |(key, value), hash|
171
+ hash[key] = translate(shape.member(key), value)
172
+ end
173
+ else
174
+ values
175
+ end
176
+ end
177
+
178
+ def list(ref, values)
179
+ return values unless values.is_a?(Array)
180
+ member_ref = ref.shape.member
181
+ values.inject([]) do |list, value|
182
+ list << translate(member_ref, value)
183
+ end
184
+ end
185
+
186
+ def map(ref, values)
187
+ return values unless values.is_a?(Hash)
188
+ value_ref = ref.shape.value
189
+ values.each.with_object({}) do |(key, value), hash|
190
+ hash[key] = translate(value_ref, value)
191
+ end
192
+ end
193
+
194
+ def translate(ref, value)
195
+ if ClientApi::AttributeValue === ref.shape
196
+ AttributeValue.new.send(@mode, value)
197
+ else
198
+ translate_complex(ref, value)
199
+ end
200
+ end
201
+
202
+ def translate_complex(ref, value)
203
+ case ref.shape
204
+ when StructureShape then structure(ref, value)
205
+ when ListShape then list(ref, value)
206
+ when MapShape then map(ref, value)
207
+ else value
208
+ end
209
+ end
210
+
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,517 @@
1
+ # WARNING ABOUT GENERATED CODE
2
+ #
3
+ # This file is generated. See the contributing for info on making contributions:
4
+ # https://github.com/aws/aws-sdk-ruby/blob/master/CONTRIBUTING.md
5
+ #
6
+ # WARNING ABOUT GENERATED CODE
7
+
8
+ module Aws
9
+ module DynamoDB
10
+ class Resource
11
+
12
+ # @param options ({})
13
+ # @option options [Client] :client
14
+ def initialize(options = {})
15
+ @client = options[:client] || Client.new(options)
16
+ end
17
+
18
+ # @return [Client]
19
+ def client
20
+ @client
21
+ end
22
+
23
+ # @!group Actions
24
+
25
+ # @example Request syntax with placeholder values
26
+ #
27
+ # dynamo_db.batch_get_item({
28
+ # request_items: { # required
29
+ # "TableName" => {
30
+ # keys: [ # required
31
+ # {
32
+ # "AttributeName" => "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
33
+ # },
34
+ # ],
35
+ # attributes_to_get: ["AttributeName"],
36
+ # consistent_read: false,
37
+ # projection_expression: "ProjectionExpression",
38
+ # expression_attribute_names: {
39
+ # "ExpressionAttributeNameVariable" => "AttributeName",
40
+ # },
41
+ # },
42
+ # },
43
+ # return_consumed_capacity: "INDEXES", # accepts INDEXES, TOTAL, NONE
44
+ # })
45
+ # @param [Hash] options ({})
46
+ # @option options [required, Hash<String,Types::KeysAndAttributes>] :request_items
47
+ # A map of one or more table names and, for each table, a map that
48
+ # describes one or more items to retrieve from that table. Each table
49
+ # name can be used only once per *BatchGetItem* request.
50
+ #
51
+ # Each element in the map of items to retrieve consists of the
52
+ # following:
53
+ #
54
+ # * *ConsistentRead* - If `true`, a strongly consistent read is used; if
55
+ # `false` (the default), an eventually consistent read is used.
56
+ #
57
+ # * *ExpressionAttributeNames* - One or more substitution tokens for
58
+ # attribute names in the *ProjectionExpression* parameter. The
59
+ # following are some use cases for using *ExpressionAttributeNames*\:
60
+ #
61
+ # * To access an attribute whose name conflicts with a DynamoDB
62
+ # reserved word.
63
+ #
64
+ # * To create a placeholder for repeating occurrences of an attribute
65
+ # name in an expression.
66
+ #
67
+ # * To prevent special characters in an attribute name from being
68
+ # misinterpreted in an expression.
69
+ #
70
+ # Use the **#** character in an expression to dereference an attribute
71
+ # name. For example, consider the following attribute name:
72
+ #
73
+ # * `Percentile`
74
+ #
75
+ # ^
76
+ #
77
+ # The name of this attribute conflicts with a reserved word, so it
78
+ # cannot be used directly in an expression. (For the complete list of
79
+ # reserved words, see [Reserved Words][1] in the *Amazon DynamoDB
80
+ # Developer Guide*). To work around this, you could specify the
81
+ # following for *ExpressionAttributeNames*\:
82
+ #
83
+ # * `\{"#P":"Percentile"\}`
84
+ #
85
+ # ^
86
+ #
87
+ # You could then use this substitution in an expression, as in this
88
+ # example:
89
+ #
90
+ # * `#P = :val`
91
+ #
92
+ # ^
93
+ #
94
+ # <note markdown="1"> Tokens that begin with the **\:** character are *expression
95
+ # attribute values*, which are placeholders for the actual value at
96
+ # runtime.
97
+ #
98
+ # </note>
99
+ #
100
+ # For more information on expression attribute names, see [Accessing
101
+ # Item Attributes][2] in the *Amazon DynamoDB Developer Guide*.
102
+ #
103
+ # * *Keys* - An array of primary key attribute values that define
104
+ # specific items in the table. For each primary key, you must provide
105
+ # *all* of the key attributes. For example, with a simple primary key,
106
+ # you only need to provide the partition key value. For a composite
107
+ # key, you must provide *both* the partition key value and the sort
108
+ # key value.
109
+ #
110
+ # * *ProjectionExpression* - A string that identifies one or more
111
+ # attributes to retrieve from the table. These attributes can include
112
+ # scalars, sets, or elements of a JSON document. The attributes in the
113
+ # expression must be separated by commas.
114
+ #
115
+ # If no attribute names are specified, then all attributes will be
116
+ # returned. If any of the requested attributes are not found, they
117
+ # will not appear in the result.
118
+ #
119
+ # For more information, see [Accessing Item Attributes][2] in the
120
+ # *Amazon DynamoDB Developer Guide*.
121
+ #
122
+ # * *AttributesToGet* -
123
+ #
124
+ # This is a legacy parameter, for backward compatibility. New
125
+ # applications should use *ProjectionExpression* instead. Do not
126
+ # combine legacy parameters and expression parameters in a single API
127
+ # call; otherwise, DynamoDB will return a *ValidationException*
128
+ # exception.
129
+ #
130
+ # This parameter allows you to retrieve attributes of type List or
131
+ # Map; however, it cannot retrieve individual elements within a List
132
+ # or a Map.
133
+ #
134
+ # The names of one or more attributes to retrieve. If no attribute
135
+ # names are provided, then all attributes will be returned. If any of
136
+ # the requested attributes are not found, they will not appear in the
137
+ # result.
138
+ #
139
+ # Note that *AttributesToGet* has no effect on provisioned throughput
140
+ # consumption. DynamoDB determines capacity units consumed based on
141
+ # item size, not on the amount of data that is returned to an
142
+ # application.
143
+ #
144
+ #
145
+ #
146
+ # [1]: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html
147
+ # [2]: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.AccessingItemAttributes.html
148
+ # @option options [String] :return_consumed_capacity
149
+ # Determines the level of detail about provisioned throughput
150
+ # consumption that is returned in the response:
151
+ #
152
+ # * *INDEXES* - The response includes the aggregate *ConsumedCapacity*
153
+ # for the operation, together with *ConsumedCapacity* for each table
154
+ # and secondary index that was accessed.
155
+ #
156
+ # Note that some operations, such as *GetItem* and *BatchGetItem*, do
157
+ # not access any indexes at all. In these cases, specifying *INDEXES*
158
+ # will only return *ConsumedCapacity* information for table(s).
159
+ #
160
+ # * *TOTAL* - The response includes only the aggregate
161
+ # *ConsumedCapacity* for the operation.
162
+ #
163
+ # * *NONE* - No *ConsumedCapacity* details are included in the response.
164
+ # @return [Types::BatchGetItemOutput]
165
+ def batch_get_item(options = {})
166
+ resp = @client.batch_get_item(options)
167
+ resp.data
168
+ end
169
+
170
+ # @example Request syntax with placeholder values
171
+ #
172
+ # dynamo_db.batch_write_item({
173
+ # request_items: { # required
174
+ # "TableName" => [
175
+ # {
176
+ # put_request: {
177
+ # item: { # required
178
+ # "AttributeName" => "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
179
+ # },
180
+ # },
181
+ # delete_request: {
182
+ # key: { # required
183
+ # "AttributeName" => "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
184
+ # },
185
+ # },
186
+ # },
187
+ # ],
188
+ # },
189
+ # return_consumed_capacity: "INDEXES", # accepts INDEXES, TOTAL, NONE
190
+ # return_item_collection_metrics: "SIZE", # accepts SIZE, NONE
191
+ # })
192
+ # @param [Hash] options ({})
193
+ # @option options [required, Hash<String,Array>] :request_items
194
+ # A map of one or more table names and, for each table, a list of
195
+ # operations to be performed (*DeleteRequest* or *PutRequest*). Each
196
+ # element in the map consists of the following:
197
+ #
198
+ # * *DeleteRequest* - Perform a *DeleteItem* operation on the specified
199
+ # item. The item to be deleted is identified by a *Key* subelement:
200
+ #
201
+ # * *Key* - A map of primary key attribute values that uniquely
202
+ # identify the ! item. Each entry in this map consists of an
203
+ # attribute name and an attribute value. For each primary key, you
204
+ # must provide *all* of the key attributes. For example, with a
205
+ # simple primary key, you only need to provide a value for the
206
+ # partition key. For a composite primary key, you must provide
207
+ # values for *both* the partition key and the sort key.
208
+ #
209
+ # ^
210
+ #
211
+ # * *PutRequest* - Perform a *PutItem* operation on the specified item.
212
+ # The item to be put is identified by an *Item* subelement:
213
+ #
214
+ # * *Item* - A map of attributes and their values. Each entry in this
215
+ # map consists of an attribute name and an attribute value.
216
+ # Attribute values must not be null; string and binary type
217
+ # attributes must have lengths greater than zero; and set type
218
+ # attributes must not be empty. Requests that contain empty values
219
+ # will be rejected with a *ValidationException* exception.
220
+ #
221
+ # If you specify any attributes that are part of an index key, then
222
+ # the data types for those attributes must match those of the schema
223
+ # in the table's attribute definition.
224
+ # @option options [String] :return_consumed_capacity
225
+ # Determines the level of detail about provisioned throughput
226
+ # consumption that is returned in the response:
227
+ #
228
+ # * *INDEXES* - The response includes the aggregate *ConsumedCapacity*
229
+ # for the operation, together with *ConsumedCapacity* for each table
230
+ # and secondary index that was accessed.
231
+ #
232
+ # Note that some operations, such as *GetItem* and *BatchGetItem*, do
233
+ # not access any indexes at all. In these cases, specifying *INDEXES*
234
+ # will only return *ConsumedCapacity* information for table(s).
235
+ #
236
+ # * *TOTAL* - The response includes only the aggregate
237
+ # *ConsumedCapacity* for the operation.
238
+ #
239
+ # * *NONE* - No *ConsumedCapacity* details are included in the response.
240
+ # @option options [String] :return_item_collection_metrics
241
+ # Determines whether item collection metrics are returned. If set to
242
+ # `SIZE`, the response includes statistics about item collections, if
243
+ # any, that were modified during the operation are returned in the
244
+ # response. If set to `NONE` (the default), no statistics are returned.
245
+ # @return [Types::BatchWriteItemOutput]
246
+ def batch_write_item(options = {})
247
+ resp = @client.batch_write_item(options)
248
+ resp.data
249
+ end
250
+
251
+ # @example Request syntax with placeholder values
252
+ #
253
+ # table = dynamo_db.create_table({
254
+ # attribute_definitions: [ # required
255
+ # {
256
+ # attribute_name: "KeySchemaAttributeName", # required
257
+ # attribute_type: "S", # required, accepts S, N, B
258
+ # },
259
+ # ],
260
+ # table_name: "TableName", # required
261
+ # key_schema: [ # required
262
+ # {
263
+ # attribute_name: "KeySchemaAttributeName", # required
264
+ # key_type: "HASH", # required, accepts HASH, RANGE
265
+ # },
266
+ # ],
267
+ # local_secondary_indexes: [
268
+ # {
269
+ # index_name: "IndexName", # required
270
+ # key_schema: [ # required
271
+ # {
272
+ # attribute_name: "KeySchemaAttributeName", # required
273
+ # key_type: "HASH", # required, accepts HASH, RANGE
274
+ # },
275
+ # ],
276
+ # projection: { # required
277
+ # projection_type: "ALL", # accepts ALL, KEYS_ONLY, INCLUDE
278
+ # non_key_attributes: ["NonKeyAttributeName"],
279
+ # },
280
+ # },
281
+ # ],
282
+ # global_secondary_indexes: [
283
+ # {
284
+ # index_name: "IndexName", # required
285
+ # key_schema: [ # required
286
+ # {
287
+ # attribute_name: "KeySchemaAttributeName", # required
288
+ # key_type: "HASH", # required, accepts HASH, RANGE
289
+ # },
290
+ # ],
291
+ # projection: { # required
292
+ # projection_type: "ALL", # accepts ALL, KEYS_ONLY, INCLUDE
293
+ # non_key_attributes: ["NonKeyAttributeName"],
294
+ # },
295
+ # provisioned_throughput: { # required
296
+ # read_capacity_units: 1, # required
297
+ # write_capacity_units: 1, # required
298
+ # },
299
+ # },
300
+ # ],
301
+ # provisioned_throughput: { # required
302
+ # read_capacity_units: 1, # required
303
+ # write_capacity_units: 1, # required
304
+ # },
305
+ # stream_specification: {
306
+ # stream_enabled: false,
307
+ # stream_view_type: "NEW_IMAGE", # accepts NEW_IMAGE, OLD_IMAGE, NEW_AND_OLD_IMAGES, KEYS_ONLY
308
+ # },
309
+ # })
310
+ # @param [Hash] options ({})
311
+ # @option options [required, Array<Types::AttributeDefinition>] :attribute_definitions
312
+ # An array of attributes that describe the key schema for the table and
313
+ # indexes.
314
+ # @option options [required, String] :table_name
315
+ # The name of the table to create.
316
+ # @option options [required, Array<Types::KeySchemaElement>] :key_schema
317
+ # Specifies the attributes that make up the primary key for a table or
318
+ # an index. The attributes in *KeySchema* must also be defined in the
319
+ # *AttributeDefinitions* array. For more information, see [Data
320
+ # Model][1] in the *Amazon DynamoDB Developer Guide*.
321
+ #
322
+ # Each *KeySchemaElement* in the array is composed of:
323
+ #
324
+ # * *AttributeName* - The name of this key attribute.
325
+ #
326
+ # * *KeyType* - The role that the key attribute will assume:
327
+ #
328
+ # * `HASH` - partition key
329
+ #
330
+ # * `RANGE` - sort key
331
+ #
332
+ # <note markdown="1"> The partition key of an item is also known as its *hash attribute*.
333
+ # The term "hash attribute" derives from DynamoDB' usage of an
334
+ # internal hash function to evenly distribute data items across
335
+ # partitions, based on their partition key values.
336
+ #
337
+ # The sort key of an item is also known as its *range attribute*. The
338
+ # term "range attribute" derives from the way DynamoDB stores items
339
+ # with the same partition key physically close together, in sorted order
340
+ # by the sort key value.
341
+ #
342
+ # </note>
343
+ #
344
+ # For a simple primary key (partition key), you must provide exactly one
345
+ # element with a *KeyType* of `HASH`.
346
+ #
347
+ # For a composite primary key (partition key and sort key), you must
348
+ # provide exactly two elements, in this order: The first element must
349
+ # have a *KeyType* of `HASH`, and the second element must have a
350
+ # *KeyType* of `RANGE`.
351
+ #
352
+ # For more information, see [Specifying the Primary Key][2] in the
353
+ # *Amazon DynamoDB Developer Guide*.
354
+ #
355
+ #
356
+ #
357
+ # [1]: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html
358
+ # [2]: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html#WorkingWithTables.primary.key
359
+ # @option options [Array<Types::LocalSecondaryIndex>] :local_secondary_indexes
360
+ # One or more local secondary indexes (the maximum is five) to be
361
+ # created on the table. Each index is scoped to a given partition key
362
+ # value. There is a 10 GB size limit per partition key value; otherwise,
363
+ # the size of a local secondary index is unconstrained.
364
+ #
365
+ # Each local secondary index in the array includes the following:
366
+ #
367
+ # * *IndexName* - The name of the local secondary index. Must be unique
368
+ # only for this table.
369
+ #
370
+ #
371
+ #
372
+ # * *KeySchema* - Specifies the key schema for the local secondary
373
+ # index. The key schema must begin with the same partition key as the
374
+ # table.
375
+ #
376
+ # * *Projection* - Specifies attributes that are copied (projected) from
377
+ # the table into the index. These are in addition to the primary key
378
+ # attributes and index key attributes, which are automatically
379
+ # projected. Each attribute specification is composed of:
380
+ #
381
+ # * *ProjectionType* - One of the following:
382
+ #
383
+ # * `KEYS_ONLY` - Only the index and primary keys are projected into
384
+ # the index.
385
+ #
386
+ # * `INCLUDE` - Only the specified table attributes are projected
387
+ # into the index. The list of projected attributes are in
388
+ # *NonKeyAttributes*.
389
+ #
390
+ # * `ALL` - All of the table attributes are projected into the
391
+ # index.
392
+ #
393
+ # * *NonKeyAttributes* - A list of one or more non-key attribute names
394
+ # that are projected into the secondary index. The total count of
395
+ # attributes provided in *NonKeyAttributes*, summed across all of
396
+ # the secondary indexes, must not exceed 20. If you project the same
397
+ # attribute into two different indexes, this counts as two distinct
398
+ # attributes when determining the total.
399
+ # @option options [Array<Types::GlobalSecondaryIndex>] :global_secondary_indexes
400
+ # One or more global secondary indexes (the maximum is five) to be
401
+ # created on the table. Each global secondary index in the array
402
+ # includes the following:
403
+ #
404
+ # * *IndexName* - The name of the global secondary index. Must be unique
405
+ # only for this table.
406
+ #
407
+ #
408
+ #
409
+ # * *KeySchema* - Specifies the key schema for the global secondary
410
+ # index.
411
+ #
412
+ # * *Projection* - Specifies attributes that are copied (projected) from
413
+ # the table into the index. These are in addition to the primary key
414
+ # attributes and index key attributes, which are automatically
415
+ # projected. Each attribute specification is composed of:
416
+ #
417
+ # * *ProjectionType* - One of the following:
418
+ #
419
+ # * `KEYS_ONLY` - Only the index and primary keys are projected into
420
+ # the index.
421
+ #
422
+ # * `INCLUDE` - Only the specified table attributes are projected
423
+ # into the index. The list of projected attributes are in
424
+ # *NonKeyAttributes*.
425
+ #
426
+ # * `ALL` - All of the table attributes are projected into the
427
+ # index.
428
+ #
429
+ # * *NonKeyAttributes* - A list of one or more non-key attribute names
430
+ # that are projected into the secondary index. The total count of
431
+ # attributes provided in *NonKeyAttributes*, summed across all of
432
+ # the secondary indexes, must not exceed 20. If you project the same
433
+ # attribute into two different indexes, this counts as two distinct
434
+ # attributes when determining the total.
435
+ #
436
+ # * *ProvisionedThroughput* - The provisioned throughput settings for
437
+ # the global secondary index, consisting of read and write capacity
438
+ # units.
439
+ # @option options [required, Types::ProvisionedThroughput] :provisioned_throughput
440
+ # Represents the provisioned throughput settings for a specified table
441
+ # or index. The settings can be modified using the *UpdateTable*
442
+ # operation.
443
+ #
444
+ # For current minimum and maximum provisioned throughput values, see
445
+ # [Limits][1] in the *Amazon DynamoDB Developer Guide*.
446
+ #
447
+ #
448
+ #
449
+ # [1]: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html
450
+ # @option options [Types::StreamSpecification] :stream_specification
451
+ # The settings for DynamoDB Streams on the table. These settings consist
452
+ # of:
453
+ #
454
+ # * *StreamEnabled* - Indicates whether Streams is to be enabled (true)
455
+ # or disabled (false).
456
+ #
457
+ # * *StreamViewType* - When an item in the table is modified,
458
+ # *StreamViewType* determines what information is written to the
459
+ # table's stream. Valid values for *StreamViewType* are:
460
+ #
461
+ # * *KEYS\_ONLY* - Only the key attributes of the modified item are
462
+ # written to the stream.
463
+ #
464
+ # * *NEW\_IMAGE* - The entire item, as it appears after it was
465
+ # modified, is written to the stream.
466
+ #
467
+ # * *OLD\_IMAGE* - The entire item, as it appeared before it was
468
+ # modified, is written to the stream.
469
+ #
470
+ # * *NEW\_AND\_OLD\_IMAGES* - Both the new and the old item images of
471
+ # the item are written to the stream.
472
+ # @return [Table]
473
+ def create_table(options = {})
474
+ resp = @client.create_table(options)
475
+ Table.new(
476
+ name: resp.data.table_description.table_name,
477
+ data: resp.data.table_description,
478
+ client: @client
479
+ )
480
+ end
481
+
482
+ # @!group Associations
483
+
484
+ # @param [String] name
485
+ # @return [Table]
486
+ def table(name)
487
+ Table.new(
488
+ name: name,
489
+ client: @client
490
+ )
491
+ end
492
+
493
+ # @example Request syntax with placeholder values
494
+ #
495
+ # tables = dynamo_db.tables()
496
+ # @param [Hash] options ({})
497
+ # @return [Table::Collection]
498
+ def tables(options = {})
499
+ batches = Enumerator.new do |y|
500
+ resp = @client.list_tables(options)
501
+ resp.each_page do |page|
502
+ batch = []
503
+ page.data.table_names.each do |t|
504
+ batch << Table.new(
505
+ name: t,
506
+ client: @client
507
+ )
508
+ end
509
+ y.yield(batch)
510
+ end
511
+ end
512
+ Table::Collection.new(batches)
513
+ end
514
+
515
+ end
516
+ end
517
+ end