{"id":21517820,"url":"https://github.com/brokenhandsio/vapor-dynamodb-sessions","last_synced_at":"2025-04-09T21:44:10.419Z","repository":{"id":63906626,"uuid":"399915146","full_name":"brokenhandsio/vapor-dynamodb-sessions","owner":"brokenhandsio","description":"A DynamoDB integration for Vapor's Sessions","archived":false,"fork":false,"pushed_at":"2021-08-26T10:03:01.000Z","size":42,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-02T22:18:49.754Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brokenhandsio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-25T18:10:33.000Z","updated_at":"2024-10-05T20:08:45.000Z","dependencies_parsed_at":"2022-11-28T22:47:53.545Z","dependency_job_id":null,"html_url":"https://github.com/brokenhandsio/vapor-dynamodb-sessions","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brokenhandsio%2Fvapor-dynamodb-sessions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brokenhandsio%2Fvapor-dynamodb-sessions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brokenhandsio%2Fvapor-dynamodb-sessions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brokenhandsio%2Fvapor-dynamodb-sessions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brokenhandsio","download_url":"https://codeload.github.com/brokenhandsio/vapor-dynamodb-sessions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999859,"owners_count":21031046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T00:45:29.115Z","updated_at":"2025-04-09T21:44:10.393Z","avatar_url":"https://github.com/brokenhandsio.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vapor DynamoDB Sessions\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://vapor.codes\"\u003e\n        \u003cimg src=\"http://img.shields.io/badge/Vapor-4-brightgreen.svg\" alt=\"Language\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://swift.org\"\u003e\n        \u003cimg src=\"http://img.shields.io/badge/Swift-5.2-brightgreen.svg\" alt=\"Language\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/brokenhandsio/vapor-dynamodb-sessions/actions\"\u003e\n         \u003cimg src=\"https://github.com/brokenhandsio/vapor-dynamodb-sessions/workflows/CI/badge.svg?branch=main\" alt=\"Build Status\"\u003e\n    \u003ca href=\"https://codecov.io/gh/brokenhandsio/vapor-dynamodb-sessions\"\u003e\n        \u003cimg src=\"https://codecov.io/gh/brokenhandsio/vapor-dynamodb-sessions/branch/main/graph/badge.svg\" alt=\"Code Coverage\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://raw.githubusercontent.com/brokenhandsio/vapor-dynamodb-sessions/main/LICENSE\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg\" alt=\"MIT License\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\nA simple library to use DynamoDB with [Soto](https://github.com/soto-project/soto) to back Vapor's sessions.\n\n## Installation\n\nAdd the library in your dependencies array in **Package.swift**:\n\n```swift\ndependencies: [\n    // ...,\n    package(name: \"VaporDynamoDBSessions\", url: \"https://github.com/brokenhandsio/vapor-dynamodb-sessions.git\", from: \"1.0.0\"),\n],\n```\n\nAlso ensure you add it as a dependency to your target:\n\n```swift\ntargets: [\n    .target(name: \"App\", dependencies: [\n        .product(name: \"Vapor\", package: \"vapor\"), \n        // ..., \n        .product(name: \"VaporDynamoDBSessions\", package: \"VaporDynamoDBSessions\")\n    ]),\n    // ...\n]\n```\n\n## Usage\n\nTo start, you must configure the `DynamoDBSessionsProvider` with the `AWSClient` and a table name. In **configure.swift** set the provider on the application:\n\n```swift\napp.dynamoDBSessions.provider = DynamoDBSessionsProvider(client: app.aws.client, tableName: tableName)\n```\n\nThe `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](https://soto.codes/user-guides/using-soto-with-vapor.html).\n\nNext, tell Vapor to use DynamoDB for sessions:\n\n```swift\napp.sessions.use(.dynamodb)\napp.middleware.use(app.sessions.middleware)\n```\n\n**Note**: You must set DynamoDB as the `SessionDriver` before adding the `SessionsMiddleware`.\n\n### Database Requirements\n\n`VaporDynamoDBSessions` will work with its own table or as part of an application using a [single-table design](https://www.alexdebrie.com/posts/dynamodb-single-table/). 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`.\n\n## Session Expiry\n\n`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:\n\n```swift\n// 30 days\nlet sessionLength: TimeInterval = 60 * 60 * 24 * 30\napp.dynamoDBSessions.provider = DynamoDBSessionsProvider(client: app.aws.client, tableName: tableName, region: .useast1, endpoint: dynamoDBEndpoint, sessionLength: sessionLength)\n```\n\nThis will add a field to the session \u0010record with the key `expiryDate` as a `number` in epoch time. This allows you to use DynamoDB's [TTL](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html) feature to auto-delete expired session data and clean up the database.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrokenhandsio%2Fvapor-dynamodb-sessions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrokenhandsio%2Fvapor-dynamodb-sessions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrokenhandsio%2Fvapor-dynamodb-sessions/lists"}