Module: Aws::SessionStore::DynamoDB::Table

Defined in:
lib/aws/session_store/dynamo_db/table.rb

Overview

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

Class Method Summary collapse

Class Method Details

.create_table(options = {}) ⇒ Object

Creates a session table.

Options Hash (options):

  • :table_name (String) — default: "sessions"

    Name of the session table.

  • :table_key (String) — default: "session_id"

    The hash key of the session table.

  • :secret_key (String)

    Secret key for HMAC encryption.

  • :consistent_read (Boolean) — default: true

    If true, a strongly consistent read is used. If false, an eventually consistent read is used. @see docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html

  • :read_capacity (Integer) — default: 10

    The maximum number of strongly consistent reads consumed per second before DynamoDB raises a ThrottlingException. @see docs.aws.amazon.com/amazondynamodb/latest/developerguide/read-write-operations.html

  • :write_capacity (Integer) — default: 5

    The maximum number of writes consumed per second before DynamoDB returns a ThrottlingException. @see docs.aws.amazon.com/amazondynamodb/latest/developerguide/read-write-operations.html

  • :raise_errors (Boolean) — default: false

    If true, all errors are raised up the stack when default ErrorHandler. If false, Only specified errors are raised up the stack when the default ErrorHandler is used.

  • :error_handler (#handle_error) — default: Errors::DefaultHandler

    An error handling object that handles all exceptions thrown during execution of the rack application.

  • :max_age (Integer) — default: nil

    Maximum number of seconds earlier from the current time that a session was created.

  • :max_stale (Integer) — default: nil

    Maximum number of seconds before current time that session was last accessed.

  • :enable_locking (Integer) — default: false

    If true, a pessimistic locking strategy will be used for all session accesses.

  • :lock_expiry_time (Integer) — default: 500

    Time in milliseconds after which the lock expires on session.

  • :lock_retry_delay (Integer) — default: 500

    Time in milliseconds to wait before retrying to obtain lock once an attempt to obtain the lock has been made and has failed.

  • :lock_max_wait_time (Integer) — default: 500

    Maximum time in seconds to wait to acquire the lock before giving up.

  • :config_file (String, Pathname)

    Path to a YAML file that contains configuration options.

  • :dynamo_db_client (Aws::DynamoDB::Client) — default: Aws::DynamoDB::Client.new

    DynamoDB client used to perform database operations inside of the rack application.



12
13
14
15
16
17
18
19
20
# 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 = {}) ⇒ Object

Deletes a session table.

Options Hash (options):

  • :table_name (String) — default: "sessions"

    Name of the session table.

  • :table_key (String) — default: "session_id"

    The hash key of the session table.

  • :secret_key (String)

    Secret key for HMAC encryption.

  • :consistent_read (Boolean) — default: true

    If true, a strongly consistent read is used. If false, an eventually consistent read is used. @see docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html

  • :read_capacity (Integer) — default: 10

    The maximum number of strongly consistent reads consumed per second before DynamoDB raises a ThrottlingException. @see docs.aws.amazon.com/amazondynamodb/latest/developerguide/read-write-operations.html

  • :write_capacity (Integer) — default: 5

    The maximum number of writes consumed per second before DynamoDB returns a ThrottlingException. @see docs.aws.amazon.com/amazondynamodb/latest/developerguide/read-write-operations.html

  • :raise_errors (Boolean) — default: false

    If true, all errors are raised up the stack when default ErrorHandler. If false, Only specified errors are raised up the stack when the default ErrorHandler is used.

  • :error_handler (#handle_error) — default: Errors::DefaultHandler

    An error handling object that handles all exceptions thrown during execution of the rack application.

  • :max_age (Integer) — default: nil

    Maximum number of seconds earlier from the current time that a session was created.

  • :max_stale (Integer) — default: nil

    Maximum number of seconds before current time that session was last accessed.

  • :enable_locking (Integer) — default: false

    If true, a pessimistic locking strategy will be used for all session accesses.

  • :lock_expiry_time (Integer) — default: 500

    Time in milliseconds after which the lock expires on session.

  • :lock_retry_delay (Integer) — default: 500

    Time in milliseconds to wait before retrying to obtain lock once an attempt to obtain the lock has been made and has failed.

  • :lock_max_wait_time (Integer) — default: 500

    Maximum time in seconds to wait to acquire the lock before giving up.

  • :config_file (String, Pathname)

    Path to a YAML file that contains configuration options.

  • :dynamo_db_client (Aws::DynamoDB::Client) — default: Aws::DynamoDB::Client.new

    DynamoDB client used to perform database operations inside of the rack application.



24
25
26
27
28
29
# 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