Class: Aws::SessionStore::DynamoDB::Configuration
- Inherits:
-
Object
- Object
- Aws::SessionStore::DynamoDB::Configuration
- Defined in:
- lib/aws/session_store/dynamo_db/configuration.rb
Overview
This class provides a Configuration object for all DynamoDB session store operations by pulling configuration options from Runtime, a YAML file, the ENV, and default settings, in that order.
Environment Variables
The Configuration object can load default values from your environment. All configuration keys are supported except for ‘:dynamo_db_client` and `:error_handler`. The keys take the form of DYNAMO_DB_SESSION_<KEY_NAME>. Example:
export DYNAMO_DB_SESSION_TABLE_NAME='Sessions'
export DYNAMO_DB_SESSION_TABLE_KEY='id'
Locking Strategy
By default, locking is disabled for session store access. To enable locking, set the ‘:enable_locking` option to true. The locking strategy is pessimistic, meaning that only one read can be made on a session at once. While the session is being read by the process with the lock, other processes may try to obtain a lock on the same session but will be blocked. See the initializer for how to configure the pessimistic locking strategy to your needs.
Handling Errors
There are two configurable options for error handling: ‘:raise_errors` and `:error_handler`.
If you would like to use the Default Error Handler, you can decide to set ‘:raise_errors` to true or false depending on whether you want all errors, regardless of class, to be raised up the stack and essentially throw a 500.
If you decide to use your own Error Handler, you must implement the ‘BaseErrorHandler` class and pass it into the `:error_handler` option.
DynamoDB Specific Options
You may configure the table name and table hash key value of your session table with the ‘:table_name` and `:table_key` options. You may also configure performance options for your table with the `:consistent_read`, `:read_capacity`, `:write_capacity`. For more information about these configurations see {docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#create_table-instance_method CreateTable } method for Amazon DynamoDB.
Constant Summary collapse
- MEMBERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ table_name: 'sessions', table_key: 'session_id', secret_key: nil, consistent_read: true, read_capacity: 10, write_capacity: 5, raise_errors: false, error_handler: nil, max_age: nil, max_stale: nil, enable_locking: false, lock_expiry_time: 500, lock_retry_delay: 500, lock_max_wait_time: 1, config_file: nil, dynamo_db_client: nil }.freeze
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Configuration
constructor
Provides configuration object that allows access to options defined during Runtime, in a YAML file, in the ENV, and by default.
-
#to_hash ⇒ Hash
The merged configuration hash.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Provides configuration object that allows access to options defined during Runtime, in a YAML file, in the ENV, and by default.
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 101 def initialize( = {}) opts = ().merge() 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 |
Instance Method Details
#to_hash ⇒ Hash
Returns The merged configuration hash.
118 119 120 121 122 |
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 118 def to_hash MEMBERS.each_with_object({}) do |(key, _), hash| hash[key] = send(key) end end |