I am playing with amazon dynamodb no-sql database from past few days and wondering that if there is any feature time to live (TTL) of a item, so that when item reached at that value it automatically deleted from table as per the TTL value, instead of doing manually batch delete item.
4 Answers
Yes, Amazon released the time to live (TTL) feature to DynamoDb in Feb 2017. You just have to go to DynamoDb on your console. Select your table. Then click Overview and enable it there.
The TTL attribute should be your column/attribute that would decide when the row should be expired/deleted.
NOTE: The ttl attribute should be of number datatype(because DynamoDb doesn't support datetime data type). So it should be in EPOCH time format.
For example:
- Linux Terminal: date +%s
- Python: import time; long(time.time())
- Java: System.currentTimeMillis() / 1000L
- JavaScript: Math.floor(Date.now() / 1000)

- 3,939
- 3
- 20
- 22
-
1Any ideas how to do this in java? – PUG Mar 28 '17 at 20:23
-
@Hassan : Use System.currentTimeMillis() / 1000L to populate the column that is a TTL attribute. – ManJan Mar 29 '17 at 21:40
-
Interesting... What if I put TTL in future? Say (java) `Instant.now().plus(28l, ChronoUnit.DAYS).getEpochSecond() / 1000` - will it delete items in 30 days (28 + 2 from dynamodb spec)? Or I am wrong – Cherry Jun 14 '18 at 08:46
-
Question. Does DynamoDB extend TTL after reads on an object during said TTL? – papaya Nov 19 '18 at 07:02
-
1@SiddarthSreeni, no, Dynamo doesn't change the contents of that key. – ur-vogel Apr 24 '19 at 21:23
-
For java this can be followed. https://stackoverflow.com/a/24703573 – fozersahin Apr 06 '21 at 15:55
EDIT: AWS released DynamoDb TTL feature in Feb 2017.
Unfortunately, the answer is pretty short: No
As a matter of fact, DynamoDB has been designed from the ground up for simplicity. No fancy features.
-
9
-
-
1
-
7TTL support has been released so this is no longer the correct answer. – JaredHatfield Mar 05 '17 at 14:04
Yes, They have recently released this feature. Go through the documentation below https://aws.amazon.com/about-aws/whats-new/2017/02/amazon-dynamodb-now-supports-automatic-item-expiration-with-time-to-live-ttl/

- 1
-
1Add some description here too, as the link you provided may not always work. – VPK Feb 28 '17 at 06:25
You can do it using AWS DynamoDB console like what is stated by Manjan's answer.
If you prefer to use a command, you can also use AWS DynamoDB CLI command:
aws dynamodb update-time-to-live
--table-name demoTable
--time-to-live-specification Enabled=true,AttributeName=ttl
You can check out this article for more information.

- 2,942
- 5
- 28
- 50