module Aws::SessionStore::DynamoDB::Table
This module provides a way to create and delete a session table.
Public Class Methods
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 12 def create_table(options = {}) config = load_config(options) config.dynamo_db_client.create_table(create_opts(config)) logger.info "Table #{config.table_name} created, waiting for activation..." config.dynamo_db_client.wait_until(:table_exists, table_name: config.table_name) logger.info "Table #{config.table_name} is now ready to use." rescue Aws::DynamoDB::Errors::ResourceInUseException logger.warn "Table #{config.table_name} already exists, skipping creation." 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 24 def delete_table(options = {}) config = load_config(options) config.dynamo_db_client.delete_table(table_name: config.table_name) config.dynamo_db_client.wait_until(:table_not_exists, table_name: config.table_name) logger.info "Table #{config.table_name} deleted." end
Private Class Methods
attributes(hash_key)
click to toggle source
@return [Hash] Attribute settings for creating the session table.
# File lib/aws/session_store/dynamo_db/table.rb, line 55 def attributes(hash_key) { attribute_definitions: [ { attribute_name: hash_key, attribute_type: 'S' } ] } end
create_opts(config)
click to toggle source
# File lib/aws/session_store/dynamo_db/table.rb, line 43 def create_opts(config) properties(config.table_name, config.table_key).merge( throughput(config.read_capacity, config.write_capacity) ) end
load_config(options = {})
click to toggle source
Loads configuration options. @option (see Configuration#initialize)
# 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
# File lib/aws/session_store/dynamo_db/table.rb, line 33 def logger @logger ||= Logger.new($stdout) end
properties(table_name, hash_key)
click to toggle source
@return Properties for the session table.
# File lib/aws/session_store/dynamo_db/table.rb, line 50 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 Schema values for the session table.
# File lib/aws/session_store/dynamo_db/table.rb, line 64 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 the session table.
# File lib/aws/session_store/dynamo_db/table.rb, line 72 def throughput(read, write) { provisioned_throughput: { read_capacity_units: read, write_capacity_units: write } } end