The DynamoDBSessionsProvider also takes an optional AWS region and endpoint if you need to configure these. To learn how to configure the AWSClient see the Soto Documentation.
Note: You must set DynamoDB as the SessionDriver before adding the SessionsMiddleware.
Database Requirements
VaporDynamoDBSessions will work with its own table or as part of an application using a single-table design. The only requirements for the library to work is that the table must have a partition key named pk and a sort key named sk.
Session Expiry
VaporDynamoDBSessions supports adding an expiry date to sessions. Any session that has expired will be discarded by the driver. To configure this, pass a session duration when configuring the provider:
This will add a field to the session record with the key expiryDate as a number in epoch time. This allows you to use DynamoDB’s TTL feature to auto-delete expired session data and clean up the database.
Vapor DynamoDB Sessions
A simple library to use DynamoDB with Soto to back Vapor’s sessions.
Installation
Add the library in your dependencies array in Package.swift:
Also ensure you add it as a dependency to your target:
Usage
To start, you must configure the
DynamoDBSessionsProvider
with theAWSClient
and a table name. In configure.swift set the provider on the application:The
DynamoDBSessionsProvider
also takes an optional AWSregion
and endpoint if you need to configure these. To learn how to configure theAWSClient
see the Soto Documentation.Next, tell Vapor to use DynamoDB for sessions:
Note: You must set DynamoDB as the
SessionDriver
before adding theSessionsMiddleware
.Database Requirements
VaporDynamoDBSessions
will work with its own table or as part of an application using a single-table design. The only requirements for the library to work is that the table must have a partition key namedpk
and a sort key namedsk
.Session Expiry
VaporDynamoDBSessions
supports adding an expiry date to sessions. Any session that has expired will be discarded by the driver. To configure this, pass a session duration when configuring the provider:This will add a field to the session record with the key
expiryDate
as anumber
in epoch time. This allows you to use DynamoDB’s TTL feature to auto-delete expired session data and clean up the database.