- Newest
- Most votes
- Most comments
Would suggest Amazon DynamoDB, which natively supports automatic Time-to-Live (TTL) expiration of items. You can store session data as key-value pairs and let DynamoDB automatically delete expired sessions without needing background jobs.
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html
Hello.
As stated in the AI-generated response from the AWS re:Post Agent, DynamoDB is recommended as the primary choice.
I would recommend ElastiCache Serverless Valkey as the second choice.
For legacy applications where integrating the AWS SDK can be challenging, ElastiCache Valkey is a recommended choice, as it allows for connectivity via standard Redis clients.
https://aws.amazon.com/jp/blogs/database/get-started-with-amazon-elasticache-for-valkey/
Yes, Amazon DynamoDB would be an excellent fit for your session management needs. It's a fully managed key-value and document database that natively supports Time to Live (TTL) functionality, which can automatically handle session expiration without requiring a background job.
For your use case, you would structure your DynamoDB table with the session ID as the primary key. You can store the user ID and other session data as attributes. The key feature for you is DynamoDB's TTL capability, which allows you to specify a timestamp attribute that DynamoDB monitors. When items reach their expiration time, DynamoDB automatically deletes them in the background—eliminating your need for a custom cleanup job.
To implement session timeout based on last access time, you would update the TTL attribute each time a session is accessed. For example, if you want a 30-minute timeout, you'd set the TTL attribute to the current time plus 1800 seconds (expressed as a Unix epoch timestamp). Each time the user accesses their session, you'd update this timestamp to extend the expiration window.
Enabling TTL on a DynamoDB table is straightforward—you simply specify which attribute name DynamoDB should use to determine expiration. The attribute name is case-sensitive and must match what you use in your read and write operations. Once enabled, DynamoDB handles the deletion of expired items automatically, typically within 48 hours of expiration, though the exact timing can vary.
DynamoDB's performance characteristics make it well-suited for session management: it provides single-digit millisecond response times, scales automatically to handle your workload, and TTL deletions don't consume write capacity or impact your application's performance. This makes it a simple, cost-effective replacement for your current relational database approach.
Sources
Enable time to live (TTL) in DynamoDB - Amazon DynamoDB
Relevant content
asked 2 years ago
asked 2 years ago
