You are viewing documentation for version 3 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: Aws::DynamoDB::Plugins::SimpleAttributes

Inherits:
Seahorse::Client::Plugin show all
Defined in:
gems/aws-sdk-dynamodb/lib/aws-sdk-dynamodb/plugins/simple_attributes.rb

Overview

Simplifies working with Amazon DynamoDB attribute values. Translates attribute values for requests and responses to sensible Ruby natives.

This plugin is enabled by default for all Client objects. You can disable this plugin by passing simple_attributes: false to the client constructor:

ddb = Aws::DynamoDB::Client.new(simple_attributes: false)

Input Examples

With this plugin enabled, simple_attributes: true:

dynamodb.put_item(
  table_name: 'aws-sdk',
  item: {
    id: 'uuid',
    age: 35,
    tags: Set.new(%w(simple attributes)),
    data: StringIO.new('data'),
    scores: [5, 4.5, 4.9, nil],
    name: {
      first: 'John',
      last: 'Doe',
    }
  }
)

With this plugin disabled, simple_attributes: false:

# note that all types are prefixed in a hash and that
# numeric types must be serialized as strings
dynamodb.put_item(
  table_name: 'aws-sdk',
  item: {
    'id' => { s: 'uuid' },
    'age' => { n: '35' },
    'tags' => { ss: ['simple', 'attributes'] },
    'data' => { b: 'data' },
    'scores' => {
      l: [
        { n: '5' },
        { n: '4.5' },
        { n: '4.9' },
        { null: true },
      ]
    },
    'name' => {
      m: {
        'first' => { s: 'John' },
        'last' => { s: 'Doe' },
      }
    }
  }
)

Output Examples

With this plugin enabled, simple_attributes: true:

resp = dynamodb.get(table_name: 'aws-sdk', key: { id: 'uuid' })
resp.item
{
  id: 'uuid',
  age: 35,
  tags: Set.new(%w(simple attributes)),
  data: StringIO.new('data'),
  scores: [5, 4.5, 4.9, nil],
  name: {
    first: 'John',
    last: 'Doe',
  }
}

With this plugin disabled, simple_attributes: false:

# note that the request `:key` had to be type prefixed
resp = dynamodb.get(table_name: 'aws-sdk', key: { 'id' => { s: 'uuid' }})
resp.item
# {
#   "id"=> <struct s='uuid', n=nil, b=nil, ss=nil, ns=nil, bs=nil, m=nil, l=nil, null=nil, bool=nil>
#   "age"=> <struct s=nil, n="35", b=nil, ss=nil, ns=nil, bs=nil, m=nil, l=nil, null=nil, bool=nil>
#   ...
# }

Defined Under Namespace

Classes: Handler

Instance Method Summary collapse

Methods inherited from Seahorse::Client::Plugin

#add_options, #after_initialize, after_initialize, #before_initialize, before_initialize, option

Methods included from Seahorse::Client::HandlerBuilder

#handle, #handle_request, #handle_response

Instance Method Details

#add_handlers(handlers, config) ⇒ Object



107
108
109
110
111
# File 'gems/aws-sdk-dynamodb/lib/aws-sdk-dynamodb/plugins/simple_attributes.rb', line 107

def add_handlers(handlers, config)
  if config.simple_attributes
    handlers.add(Handler, step: :initialize)
  end
end