AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Class: Aws::Record::Batch

Inherits:
Object
  • Object
show all
Extended by:
ClientConfiguration
Defined in:
lib/aws-record/record/batch.rb

Class Method Summary collapse

Methods included from ClientConfiguration

configure_client, dynamodb_client

Class Method Details

.write(opts = {}, &block) ⇒ Aws::Record::BatchWrite

Provides a thin wrapper to the Aws::DynamoDB::Client#batch_write_item method. Up to 25 PutItem or DeleteItem operations are supported. A single rquest may write up to 16 MB of data, with each item having a write limit of 400 KB.

Note: this operation does not support dirty attribute handling, nor does it enforce safe write operations (i.e. update vs new record checks).

This call may partially execute write operations. Failed operations are returned as Aws::Record::BatchWrite#unprocessed_items (i.e. the table fails to meet requested write capacity). Any unprocessed items may be retried by calling Aws::Record::BatchWrite#execute! again. You can determine if the request needs to be retried by calling the Aws::Record::BatchWrite#complete? method - which returns true when all operations have been completed.

Please see Batch Operations and Error Handling in the DynamoDB Developer Guide for more details.

Examples:

Usage Example

class Breakfast
  include Aws::Record
  integer_attr :id,   hash_key: true
  string_attr  :name, range_key: true
  string_attr  :body
end

# setup
eggs = Breakfast.new(id: 1, name: "eggs").save!
waffles = Breakfast.new(id: 2, name: "waffles")
pancakes = Breakfast.new(id: 3, name: "pancakes")

# batch operations
operation = Aws::Record::Batch.write(client: Breakfast.dynamodb_client) do |db|
  db.put(waffles)
  db.delete(eggs)
  db.put(pancakes)
end

# unprocessed items can be retried by calling Aws::Record::BatchWrite#execute!
operation.execute! unless operation.complete?

Parameters:

  • opts (Hash) (defaults to: {})

    the options you wish to use to create the client. Note that if you include the option :client, all other options will be ignored. See the documentation for other options in the AWS SDK for Ruby.

Options Hash (opts):

  • :client (Aws::DynamoDB::Client)

    allows you to pass in your own pre-configured client.

Returns:



74
75
76
77
78
# File 'lib/aws-record/record/batch.rb', line 74

def write(opts = {}, &block)
  batch = BatchWrite.new(client: _build_client(opts))
  block.call(batch)
  batch.execute!
end