module Aws::SessionStore::DynamoDB::Table

This class provides a way to create and delete a session table.

Public Instance Methods

attributes(hash_key) click to toggle source

@return [Hash] Attribute settings for creating a session table. @api private

# File lib/aws/session_store/dynamo_db/table.rb, line 45
def attributes(hash_key)
  attributes = [{:attribute_name => hash_key, :attribute_type => 'S'}]
  { :attribute_definitions => attributes }
end
block_until_created(config) click to toggle source

@api private

# File lib/aws/session_store/dynamo_db/table.rb, line 73
def block_until_created(config)
  created = false
  until created
    params = { :table_name => config.table_name }
    response = config.dynamo_db_client.describe_table(params)
    created = response[:table][:table_status] == 'ACTIVE'

    sleep 10
  end
end
create_table(options = {}) click to toggle source

Creates a session table. @option (see Configuration#initialize)

# File lib/aws/session_store/dynamo_db/table.rb, line 11
def create_table(options = {})
  config = load_config(options)
  ddb_options = properties(config.table_name, config.table_key).merge(
      throughput(config.read_capacity, config.write_capacity)
    )
  config.dynamo_db_client.create_table(ddb_options)
  logger << "Table #{config.table_name} created, waiting for activation...\n"
  block_until_created(config)
  logger << "Table #{config.table_name} is now ready to use.\n"
rescue Aws::DynamoDB::Errors::ResourceInUseException
  logger << "Table #{config.table_name} already exists, skipping creation.\n"
end
delete_table(options = {}) click to toggle source

Deletes a session table. @option (see Configuration#initialize)

# File lib/aws/session_store/dynamo_db/table.rb, line 26
def delete_table(options = {})
  config = load_config(options)
  config.dynamo_db_client.delete_table(:table_name => config.table_name)
end
load_config(options = {}) click to toggle source

Loads configuration options. @option (see Configuration#initialize) @api private

# File lib/aws/session_store/dynamo_db/table.rb, line 39
def load_config(options = {})
  Aws::SessionStore::DynamoDB::Configuration.new(options)
end
logger() click to toggle source

@api private

# File lib/aws/session_store/dynamo_db/table.rb, line 32
def logger
  @logger ||= Logger.new($STDOUT)
end
properties(table_name, hash_key) click to toggle source

@return Properties for Session table @api private

# File lib/aws/session_store/dynamo_db/table.rb, line 68
def properties(table_name, hash_key)
  attributes(hash_key).merge(schema(table_name, hash_key))
end
schema(table_name, hash_key) click to toggle source

@return Shema values for session table @api private

# File lib/aws/session_store/dynamo_db/table.rb, line 52
def schema(table_name, hash_key)
  {
    :table_name => table_name,
    :key_schema => [ {:attribute_name => hash_key, :key_type => 'HASH'} ]
  }
end
throughput(read, write) click to toggle source

@return Throughput for Session table @api private

# File lib/aws/session_store/dynamo_db/table.rb, line 61
def throughput(read, write)
  units = {:read_capacity_units=> read, :write_capacity_units => write}
  { :provisioned_throughput => units }
end