class Dyna::DSL::DynamoDB::Table

Attributes

result[R]

Public Class Methods

new(context, table_name, &block) click to toggle source
# File lib/dyna/dsl/table.rb, line 8
def initialize(context, table_name, &block)
  @table_name = table_name
  @context = context

  @result = Hashie::Mash.new({
    :table_name => table_name,
    :scalable_targets => [],
    :scaling_policies => [],
    :time_to_live_specification => {
      enabled: false,
      attribute_name: nil,
    }
  })
  instance_eval(&block)
end

Public Instance Methods

attribute_definition(attribute_name:, attribute_type:) click to toggle source
# File lib/dyna/dsl/table.rb, line 38
def attribute_definition(attribute_name:, attribute_type:)
  @result.attribute_definitions ||= []
  @result.attribute_definitions << {
    attribute_name: attribute_name,
    attribute_type: attribute_type,
  }
end
billing_mode(billing_mode) click to toggle source
# File lib/dyna/dsl/table.rb, line 78
def billing_mode(billing_mode)
  @result.billing_mode = billing_mode
end
global_secondary_index(index_name, &block) click to toggle source
# File lib/dyna/dsl/table.rb, line 69
def global_secondary_index(index_name, &block)
  @result.global_secondary_indexes ||= []
  index = GlobalSecondaryIndex.new
  index.instance_eval(&block)
  @result.global_secondary_indexes << {
    index_name: index_name,
  }.merge(index.result.symbolize_keys)
end
key_schema(hash:, range: nil) click to toggle source
# File lib/dyna/dsl/table.rb, line 24
def key_schema(hash:, range: nil)
  @result.key_schema = [{
    attribute_name: hash,
    key_type: 'HASH',
  }]

  if range
    @result.key_schema << {
      attribute_name: range,
      key_type: 'RANGE',
    }
  end
end
local_secondary_index(index_name, &block) click to toggle source
# File lib/dyna/dsl/table.rb, line 60
def local_secondary_index(index_name, &block)
  @result.local_secondary_indexes ||= []
  index = LocalSecondaryIndex.new
  index.instance_eval(&block)
  @result.local_secondary_indexes << {
    index_name: index_name,
  }.merge(index.result.symbolize_keys)
end
provisioned_throughput(read_capacity_units:, write_capacity_units:) click to toggle source
# File lib/dyna/dsl/table.rb, line 46
def provisioned_throughput(read_capacity_units:, write_capacity_units:)
  @result.provisioned_throughput = {
    read_capacity_units: read_capacity_units,
    write_capacity_units: write_capacity_units,
  }
end
scalable_target(scalable_dimension:, min_capacity:, max_capacity:) click to toggle source
# File lib/dyna/dsl/table.rb, line 82
def scalable_target(scalable_dimension:, min_capacity:, max_capacity:)
  @result.scalable_targets << {
    service_namespace: 'dynamodb',
    scalable_dimension: scalable_dimension,
    resource_id: "table/#{@result.table_name}",
    min_capacity: min_capacity,
    max_capacity: max_capacity,
  }
end
scaling_policy(scalable_dimension:, target_tracking_scaling_policy_configuration:) click to toggle source
# File lib/dyna/dsl/table.rb, line 92
def scaling_policy(scalable_dimension:, target_tracking_scaling_policy_configuration:)
  predefined_metric_type = 'DynamoDBWriteCapacityUtilization'
  if scalable_dimension == 'dynamodb:table:ReadCapacityUnits'
    predefined_metric_type = 'DynamoDBReadCapacityUtilization'
  end
  @result.scaling_policies << {
    policy_name: "#{predefined_metric_type}:table/#{@result.table_name}",
    policy_type: 'TargetTrackingScaling',
    resource_id: "table/#{@result.table_name}",
    scalable_dimension: scalable_dimension,
    service_namespace: 'dynamodb',
    target_tracking_scaling_policy_configuration: target_tracking_scaling_policy_configuration.merge(predefined_metric_specification: {predefined_metric_type: predefined_metric_type}),
  }
end
stream_specification(stream_enabled:, stream_view_type: nil) click to toggle source
# File lib/dyna/dsl/table.rb, line 53
def stream_specification(stream_enabled:, stream_view_type: nil)
  @result.stream_specification = {
    stream_enabled: stream_enabled,
    stream_view_type: stream_view_type,
  }
end
time_to_live_specification(enabled:, attribute_name:) click to toggle source
# File lib/dyna/dsl/table.rb, line 107
def time_to_live_specification(enabled:, attribute_name:)
  @result.time_to_live_specification = {
    enabled: enabled,
    attribute_name: attribute_name,
  }
end