Skip to content

Commit

Permalink
doc(sesison): add support for DynamoDB store (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
7nohe authored Sep 26, 2024
1 parent 2733f03 commit 17bdf9d
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion content/docs/basics/session.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ You can manage user sessions inside your AdonisJS application using the `@adonis

- `redis`: The session data is stored inside a Redis database. The redis store is recommended for apps with large volumes of session data and can scale to multi-server deployments.

- `dynamodb`: The session data is stored inside an Amazon DynamoDB table. The DynamoDB store is suitable for applications that require a highly scalable and distributed session store, especially when the infrastructure is built on AWS.

- `memory`: The session data is stored within a global memory store. The memory store is used during testing.

Alongside the inbuilt backend stores, you can also create and [register custom session stores](#creating-a-custom-session-store).
Expand Down Expand Up @@ -203,6 +205,17 @@ export default defineConfig({
redis: stores.redis({
connection: 'main'
})
dynamodb: stores.dynamodb({
clientConfig: {
// DynamoDB client config
// See: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-dynamodb/Interface/DynamoDBClientConfig/
// You can also set credentials using the environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`.
// Also, you can set the region using the environment variable `AWS_REGION`.
},
tableName: 'Session', // The table name to store the sessions. The default is `Session`.
keyAttribute: 'key', // The attribute name for the session id, default is `key`.
}),
}
// highlight-end
})
Expand Down Expand Up @@ -250,14 +263,26 @@ Make sure to first install and configure the [@adonisjs/redis](../database/redis

</dd>

<dt>

stores.dynamodb

</dt>

<dd>

Define the configuration for the `dynamodb` store. The method accepts the `clientConfig`, `tableName` and `keyAttribute` properties.

</dd>

</dl>

---

### Updating environment variables validation
If you decide to use session stores other than the default one, make sure to also update the environment variables validation for the `SESSION_DRIVER` environment variable.

We configure the `cookie` and the `redis` stores in the following example. Therefore, we should also allow the `SESSION_DRIVER` environment variable to be one of them.
We configure the `cookie`, the `redis`, and the `dynamodb` stores in the following example. Therefore, we should also allow the `SESSION_DRIVER` environment variable to be one of them.

```ts
import { defineConfig, stores } from '@adonisjs/session'
Expand Down

0 comments on commit 17bdf9d

Please sign in to comment.