1
1
# Amazon DynamoDB Session Store
2
2
3
3
The ** Amazon DynamoDB Session Store** handles sessions for Ruby web applications
4
- using a DynamoDB backend. The session store is compatible with Rails (3.x or 4.x)
5
- and other Rack based frameworks .
4
+ using a DynamoDB backend. The session store is compatible with all Rack based
5
+ frameworks. For Rails applications, use the [ ` aws-sdk-rails ` ] [ 1 ] gem .
6
6
7
7
## Installation
8
8
9
- #### Rails Installation
10
-
11
- Install the session store gem by placing the following command into your
12
- Gemfile:
13
-
14
- gem 'aws-sessionstore-dynamodb'
15
-
16
- You will need to have an existing Amazon DynamoDB session table in order for the
17
- application to work. You can generate a migration file for the session table
18
- with the following command:
19
-
20
- rails generate sessionstore:dynamodb
21
-
22
- To create the table, run migrations as normal with:
23
-
24
- rake db:migrate
25
-
26
- Change the session store to ` :dynamodb_store ` by editing
27
- ` config/initializers/session_store.rb ` to contain the following:
28
-
29
- YourAppName::Application.config.session_store :dynamodb_store
30
-
31
- You can now start your Rails application with session support.
32
-
33
- #### Basic Rack Application Installation
34
-
35
- For non-Rails applications, you can create the Amazon DynamoDB table in a
9
+ For Rack applications, you can create the Amazon DynamoDB table in a
36
10
Ruby file using the following method:
37
11
38
12
require 'aws-sessionstore-dynamodb'
@@ -66,18 +40,17 @@ discouraging sensitive data storage. It also forces strict data size
66
40
limitations. DynamoDB takes care of these concerns by allowing for a safe and
67
41
scalable storage container with a much larger data size limit for session data.
68
42
69
- Full API documentation of the library can be found on [ RubyDoc.info ] [ 1 ] .
43
+ For more developer information, see the [ Full API documentation ] [ 2 ] .
70
44
71
45
### Configuration Options
72
46
73
47
A number of options are available to be set in
74
48
` Aws::SessionStore::DynamoDB::Configuration ` , which is used by the
75
- ` RackMiddleware ` class. These options can be set in the YAML configuration
76
- file in a Rails application (located in ` config/sessionstore/dynamodb.yml ` ),
77
- directly by Ruby code, or through environment variables.
49
+ ` RackMiddleware ` class. These options can be set directly by Ruby code or
50
+ through environment variables.
78
51
79
52
The full set of options along with defaults can be found in the
80
- [ Configuration class documentation] [ 2 ] .
53
+ [ Configuration class documentation] [ 3 ] .
81
54
82
55
#### Environment Options
83
56
@@ -90,36 +63,15 @@ The example below would be a valid way to set the session table name:
90
63
91
64
export DYNAMO_DB_SESSION_TABLE_NAME='sessions'
92
65
93
- ### Rails Generator Details
94
-
95
- The generator command specified in the installation section will generate two
96
- files: a migration file, ` db/migration/VERSION_migration_name.rb ` , and a
97
- configuration YAML file, ` config/sessionstore/dynamodb.yml ` .
98
-
99
- You can run the command with an argument that will define the name of the
100
- migration file. Once the YAML file is created, you can uncomment any of the
101
- lines to set configuration options to your liking. The session store will pull
102
- options from ` config/sessionstore/dynamodb.yml ` by default if the file exists.
103
- If you do not wish to place the configuration YAML file in that location,
104
- you can also pass in a different file path to pull options from.
105
-
106
66
### Garbage Collection
107
67
108
- You may want to delete old sessions from your session table. The
109
- following examples show how to clear old sessions from your table.
110
-
111
- #### Rails
112
-
113
- A Rake task for garbage collection is provided for Rails applications.
114
- By default sessions do not expire. See ` config/sessionstore/dynamodb.yml ` to
115
- configure the max age or stale period of a session. Once you have configured
116
- those values you can clear the old sessions with:
117
-
118
- rake dynamo_db:collect_garbage
119
-
120
- #### Outside of Rails
68
+ You may want to delete old sessions from your session table. You can use the
69
+ DynamoDB [ Time to Live (TTL) feature] [ 4 ] on the ` expire_at ` attribute to
70
+ automatically delete expired items.
121
71
122
- You can create your own Rake task for garbage collection similar to below:
72
+ If you want to take other attributes into consideration for deletion, you could
73
+ instead use the ` GarbageCollection ` class. You can create your own Rake task for
74
+ garbage collection similar to below:
123
75
124
76
require "aws-sessionstore-dynamodb"
125
77
@@ -167,5 +119,7 @@ the default error handler to them for you. See the API documentation
167
119
on the {Aws::SessionStore::DynamoDB::Errors::BaseHandler} class for more
168
120
details.
169
121
170
- [ 1 ] : http://rubydoc.org/gems/aws-sessionstore-dynamodb/frames
171
- [ 2 ] : http://rubydoc.org/gems/aws-sessionstore-dynamodb/AWS/SessionStore/DynamoDB/Configuration#initialize-instance_method
122
+ [ 1 ] : https://github.com/aws/aws-sdk-rails/
123
+ [ 2 ] : https://docs.aws.amazon.com/sdk-for-ruby/aws-sessionstore-dynamodb/api/
124
+ [ 3 ] : https://docs.aws.amazon.com/sdk-for-ruby/aws-sessionstore-dynamodb/api/Aws/SessionStore/DynamoDB/Configuration.html
125
+ [ 4 ] : https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html
0 commit comments