Skip to content

Commit

Permalink
Merge pull request #40 from open-sausages/pulls/docs-gc
Browse files Browse the repository at this point in the history
DOCS Clarify GC handling, remove crontask dep (fixes #39)
  • Loading branch information
chillu authored May 26, 2020
2 parents 9e00925 + 36b2031 commit a91a8a2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
26 changes: 5 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ If you wish to store sessions in DynamoDB, set the required environment variable

Once these are in place, this module will configure DynamoDB and register that as the session handler.

Before you can actually use this, you need to create a table in which to store the sessions. This can be done through the [AWS Console for Amazon DynamoDB](https://console.aws.amazon.com/dynamodb/home), or using the SDK. When creating the table, you should set the primary key to `id` of type `string`.
Before you can actually use this, you need to create a table in which to store the sessions.
Follow the instructions in the [AWS SDK for PHP documentation](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/service_dynamodb-session-handler.html#basic-usage).

**IMPORTANT: You need to [set up a TTL attribute](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/service_dynamodb-session-handler.html#ddbsh-garbage-collection) for garbage collection in your table.
The module does not provide automated garbage collection abilities.**

## Using DynamoDB outside of AWS

Expand All @@ -40,26 +44,6 @@ in EC2 instances, as credentials are automatically handled by the IAM role insid
AWS_ACCESS_KEY=my-access-key
AWS_SECRET_KEY=my-secret

## Garbage collecting sessions

Inactive sessions are garbage collected by `GarbageCollectSessionCronTask` if [silverstripe-crontask](https://github.com/silverstripe-labs/silverstripe-crontask)
is setup on your instance. The time when a session should be collected after inactivity can be changed by setting
`Session::$timeout`.

For example, in your application's config YAML file, this sets a 20 minute session timeout:

Session:
timeout: 1200

You can also set the DynamoDB garbage collection time independently of `Session::$timeout`, but it's recommended you
make it at least the value of `Session::$timeout` or greater.

For example, in your `_ss_environment.php` file, set garbage collection after 1 hour of inactivity in sessions:

define('AWS_DYNAMODB_SESSION_LIFETIME', 3600);

See https://docs.aws.amazon.com/aws-sdk-php/v3/guide/service/dynamodb-session-handler.html for more information.

## Local Testing

You can simulate DynamoDB locally for easier development through [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SettingUp.html).
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"require": {
"aws/aws-sdk-php": "~3.105",
"doctrine/cache": "1.*",
"silverstripe/crontask": "*",
"silverstripe/framework": "^4@dev"
},
"require-dev": {
Expand Down

0 comments on commit a91a8a2

Please sign in to comment.