A developer is building a web application and wants to store user session data externally. The application requires a solution that natively supports automatically deleting expired session items after a specified period of time to keep costs low and limit storage growth, without requiring custom deletion code. Which AWS service and feature should the developer use to meet these requirements?
- AAWS Lambda execution context global variables
- Amazon DynamoDB with Time-to-Live (TTL) enabledAnswer
- CAmazon Systems Manager Parameter Store with secure strings
- DAmazon DynamoDB with a nightly application cron script that executes a Scan operation to delete expired sessions
Answer
Amazon DynamoDB with Time-to-Live (TTL) enabled is the best solution for storing session state and automatically purging expired items without custom code.
Amazon DynamoDB is a fully managed NoSQL database service that provides single-digit millisecond latency at scale. It includes a native Time-to-Live (TTL) feature that allows developers to define a timestamp attribute on items. Once the current time passes the timestamp, DynamoDB automatically deletes the item within a few days without consuming provisioned throughput, eliminating the need to write custom cleanup code.
Step-by-Step Solution
Key Concept
Storing session state externally in Amazon DynamoDB and leveraging its native Time-to-Live (TTL) feature to automate cleanup of expired records.
Alternative Method
For session data with sub-millisecond requirements that require advanced data structures, Amazon ElastiCache (Redis) can be used with a key expiration (TTL) set via the EXPIRE command.
Estimated Time:1m 0s