class Aws::SessionStore::DynamoDB::Configuration


method for Amazon DynamoDB.
{docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#create_table-instance_method CreateTable}
about these configurations see
your table with the ‘:consistent_read`, `:read_capacity`, `:write_capacity`. For more information
the `:table_name` and `:table_key` options. You may also configure performance options for
You may configure the table name and table hash key value of your session table with
# DynamoDB Specific Options
@see BaseHandler Interface for Error Handling for DynamoDB Session Store.
class and pass it into the `:error_handler` option.
If you decide to use your own Error Handler, you must implement the `BaseErrorHandler`
up the stack and essentially throw a 500.
to true or false depending on whether you want all errors, regardless of class, to be raised
If you would like to use the Default Error Handler, you can decide to set `:raise_errors`
There are two configurable options for error handling: `:raise_errors` and `:error_handler`.
# Handling Errors
See the initializer for how to configure the pessimistic locking strategy to your needs.
lock, other processes may try to obtain a lock on the same session but will be blocked.
read can be made on a session at once. While the session is being read by the process with the
`:enable_locking` option to true. The locking strategy is pessimistic, meaning that only one
By default, locking is disabled for session store access. To enable locking, set the
# Locking Strategy
export AWS_DYNAMO_DB_SESSION_TABLE_KEY=’id’
export AWS_DYNAMO_DB_SESSION_TABLE_NAME=‘Sessions’
of AWS_DYNAMO_DB_SESSION_<KEY_NAME>. Example:
keys are supported except for ‘:dynamo_db_client` and `:error_handler`. The keys take the form
The Configuration object can load default values from your environment. All configuration
# Environment Variables
settings, in that order.
by pulling configuration options from Runtime, the ENV, a YAML file, and default
This class provides a Configuration object for all DynamoDB session store operations

def default_dynamo_db_client(options)

def default_dynamo_db_client(options)
  dynamo_db_client = options[:dynamo_db_client] || Aws::DynamoDB::Client.new
  dynamo_db_client.config.user_agent_frameworks << 'aws-sessionstore-dynamodb'
  dynamo_db_client
end

def default_error_handler(options)

def default_error_handler(options)
  Aws::SessionStore::DynamoDB::Errors::DefaultHandler.new(options[:raise_errors])
end

def env_key(opt_name)

def env_key(opt_name)
  # legacy - remove this in aws-sessionstore-dynamodb ~> 4
  key = "DYNAMO_DB_SESSION_#{opt_name.to_s.upcase}"
  if ENV.key?(key)
    Kernel.warn("The environment variable `#{key}` is deprecated.
                 Please use `AWS_DYNAMO_DB_SESSION_#{opt_name.to_s.upcase}` instead.")
  else
    key = "AWS_DYNAMO_DB_SESSION_#{opt_name.to_s.upcase}"
  end
  key
end

def env_options

Returns:
  • (Hash) - Environment options.
def env_options
  unsupported_keys = %i[dynamo_db_client error_handler]
  (MEMBERS.keys - unsupported_keys).each_with_object({}) do |opt_name, opts|
    key = env_key(opt_name)
    next unless ENV.key?(key)
    opts[opt_name] = parse_env_value(key)
  end
end

def file_options(options = {})

Returns:
  • (Hash) - File options.
def file_options(options = {})
  if options[:config_file]
    load_from_file(options[:config_file])
  else
    {}
  end
end

def initialize(options = {})

Options Hash: (**options)
  • :dynamo_db_client (Aws::DynamoDB::Client) --
  • :config_file (String, Pathname) --
  • :lock_max_wait_time (Integer) -- Maximum time in seconds to wait to acquire the
  • :lock_retry_delay (Integer) -- Time in milliseconds to wait before retrying
  • :lock_expiry_time (Integer) -- Time in milliseconds after which the lock
  • :enable_locking (Integer) -- If true, a pessimistic locking strategy will be
  • :max_stale (Integer) -- Maximum number of seconds
  • :max_age (Integer) -- Maximum number of seconds earlier
  • :error_handler (#handle_error) -- An error handling object
  • :raise_errors (Boolean) -- If true, all errors are raised up the stack
  • :write_capacity (Integer) -- The maximum number of writes
  • :read_capacity (Integer) -- The maximum number of strongly consistent reads
  • :consistent_read (Boolean) -- If true, a strongly consistent read is used.
  • :secret_key (String) -- Secret key for HMAC encryption.
  • :table_key (String) -- The hash key of the session table.
  • :table_name (String) -- Name of the session table.

Other tags:
    See: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/read-write-operations.html -
    See: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/read-write-operations.html -
    See: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html -
def initialize(options = {})
  opts = options
  opts = env_options.merge(opts)
  opts = file_options(opts).merge(opts)
  MEMBERS.each_pair do |opt_name, default_value|
    opts[opt_name] = default_value unless opts.key?(opt_name)
  end
  opts = opts.merge(dynamo_db_client: default_dynamo_db_client(opts))
  opts = opts.merge(error_handler: default_error_handler(opts)) unless opts[:error_handler]
  set_attributes(opts)
end

def load_from_file(file_path)

Load options from the YAML file.
def load_from_file(file_path)
  require 'erb'
  require 'yaml'
  opts = YAML.safe_load(ERB.new(File.read(file_path)).result) || {}
  unsupported_keys = %i[dynamo_db_client error_handler config_file]
  opts.transform_keys(&:to_sym).reject { |k, _| unsupported_keys.include?(k) }
end

def parse_env_value(key)

def parse_env_value(key)
  val = ENV.fetch(key, nil)
  Integer(val)
rescue ArgumentError
  %w[true false].include?(val) ? val == 'true' : val
end

def set_attributes(options)

def set_attributes(options)
  MEMBERS.each_key do |attr_name|
    instance_variable_set("@#{attr_name}", options[attr_name])
  end
end

def to_hash

Returns:
  • (Hash) - The merged configuration hash.
def to_hash
  MEMBERS.each_with_object({}) do |(key, _), hash|
    hash[key] = send(key)
  end
end