Class: Serverspec::Type::AWS::DynamoDB::Table

Inherits:
Base
  • Object
show all
Defined in:
lib/resources/dynamodb/table.rb

Overview

The Table class exposes the DynamoDB::Table resources

Instance Method Summary collapse

Constructor Details

#initialize(tbl_name, instance = nil) ⇒ Table

AWS SDK for Ruby v2 Aws::DynamoDB::Client wrapper for initializing a Table resource

Parameters:

  • tbl_name (String)

    The name of the Table

  • instance (Class) (defaults to: nil)

    Aws::DynamoDB::Client instance

Raises:

  • (RuntimeError)

    if tbl_name.nil?

  • (ResourceNotFoundException)

    if table.nil?



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/resources/dynamodb/table.rb', line 14

def initialize(tbl_name, instance = nil)
  check_init_arg 'tbl_name', 'DynamoDB::Table', tbl_name
  @tbl_name = tbl_name
  @aws = instance.nil? ? Aws::DynamoDB::Client.new : instance
  get_table tbl_name

  @type_map = {
    'S' => :string,
    'N' => :number,
    'B' => :binary
  }
end

Instance Method Details

#attribute_definitionsArray(Hash)

An array of AttributeDefinition objects. Each of these objects describes one attribute in the Table and index key schema

Returns:

  • (Array(Hash))


61
62
63
# File 'lib/resources/dynamodb/table.rb', line 61

def attribute_definitions
  @table.attribute_definitions
end

#global_secondary_indexed?Boolean

Returns true if there is a global secondary index

Returns:

  • (Boolean)


54
55
56
# File 'lib/resources/dynamodb/table.rb', line 54

def global_secondary_indexed?
  @table.global_secondary_indexes.is_a?(Array)
end

#global_secondary_indexesArray(Hash)

The global secondary indexes, if any, on the Table. Each index is scoped to a given hash key value

Returns:

  • (Array(Hash))


95
96
97
# File 'lib/resources/dynamodb/table.rb', line 95

def global_secondary_indexes
  @table.global_secondary_indexes
end

#hash_key_nameString

The name of the hash key from the key_schema

Returns:

  • (String)


101
102
103
104
105
# File 'lib/resources/dynamodb/table.rb', line 101

def hash_key_name
  @table.key_schema.each do |key|
    return key.attribute_name if key.key_type == 'HASH'
  end
end

#hash_key_typeSymbol

The type of the hash key from the key_schema. Valid return values: :string, :number, or :binary

Returns:

  • (Symbol)


110
111
112
113
114
115
116
117
118
# File 'lib/resources/dynamodb/table.rb', line 110

def hash_key_type
  @table.attribute_definitions.each do |attr|
    if attr.attribute_name == hash_key_name
      return @type_map[
        attr.attribute_type
      ]
    end
  end
end

#key_schemaArray(Hash)

The primary key structure for the Table

Returns:

  • (Array(Hash))


67
68
69
# File 'lib/resources/dynamodb/table.rb', line 67

def key_schema
  @table.key_schema
end

#local_secondary_indexed?Boolean

Returns true if there is a local secondary index

Returns:

  • (Boolean)


49
50
51
# File 'lib/resources/dynamodb/table.rb', line 49

def local_secondary_indexed?
  @table.local_secondary_indexes.is_a?(Array)
end

#local_secondary_indexesArray(Hash)

Represents one or more local secondary indexes on the Table. Each index is scoped to a given hash key value

Returns:

  • (Array(Hash))


88
89
90
# File 'lib/resources/dynamodb/table.rb', line 88

def local_secondary_indexes
  @table.local_secondary_indexes
end

#range_key_nameString

The name of the range key from the key_schema

Returns:

  • (String)


122
123
124
125
126
# File 'lib/resources/dynamodb/table.rb', line 122

def range_key_name
  @table.key_schema.each do |key|
    return key.attribute_name if key.key_type == 'RANGE'
  end
end

#range_key_typeSymbol

The type of the range key from the key_schema. Valid return values: :string, :number, or :binary

Returns:

  • (Symbol)


131
132
133
134
135
136
137
138
139
# File 'lib/resources/dynamodb/table.rb', line 131

def range_key_type
  @table.attribute_definitions.each do |attr|
    if attr.attribute_name == range_key_name
      return @type_map[
        attr.attribute_type
      ]
    end
  end
end

#read_capacityInteger

The maximum number of strongly consistent reads consumed per second before DynamoDB returns a ThrottlingException

Returns:

  • (Integer)


74
75
76
# File 'lib/resources/dynamodb/table.rb', line 74

def read_capacity
  @table.provisioned_throughput.read_capacity_units
end

#to_sString

Returns the String representation of DynamoDB::Table

Returns:

  • (String)


29
30
31
# File 'lib/resources/dynamodb/table.rb', line 29

def to_s
  "DynamoDB Table: #{@tbl_name}"
end

#valid?Boolean

Returns true if the Table is active

Returns:

  • (Boolean)


34
35
36
# File 'lib/resources/dynamodb/table.rb', line 34

def valid?
  @table.table_status == 'ACTIVE'
end

#with_hash_key?Boolean

Returns true if the Table has a hash key

Returns:

  • (Boolean)


39
40
41
# File 'lib/resources/dynamodb/table.rb', line 39

def with_hash_key?
  key_type?('hash')
end

#with_range_key?Boolean

Returns true if the Table has a range key

Returns:

  • (Boolean)


44
45
46
# File 'lib/resources/dynamodb/table.rb', line 44

def with_range_key?
  key_type?('range')
end

#write_capacityInteger

The maximum number of writes consumed per second before DynamoDB returns a ThrottlingException

Returns:

  • (Integer)


81
82
83
# File 'lib/resources/dynamodb/table.rb', line 81

def write_capacity
  @table.provisioned_throughput.write_capacity_units
end