TTL is known as time to live. You can think of TTL as a ticking time bomb. You choose when you want the item to be deleted in the time (UNIX epoch) specified along with the item in the specified TTL attribute.
DynamoDB TTL use cases
- Delete expired auth sessions automatically
- Archive IoT sensor data from (ESP32, Greengrass)
- Delete unverified users after 48 hours
- Archive resumes of unqualified applicants from the past 6 months
- Archive old data to S3 to save DB storage cost with TTL and DynamoDB streams for auditing purposes
How to enable TTL in DynamoDB table
- Navigate to you DynamoDB table and scroll all the way right till you see Additional settings.
- In the Additional settings you’ll find Time to Live (TTL) after scrolling down a bit.
- Click Turn on button

In the TTL page put your attribute name which will be used as a TTL to delete the item at the specified time. e.g. expire_at
Click Turn on TTL

You will see TTL status On

How to test DynamoDB TTL?
Let’s create an item with TTL of 30 seconds later from current UNIX time.
Important
Make sure to use number (N) type to specify the TTL attribute.
To get the current UNIX epoch time in seconds you can use date +%s command.

- Go back to the Additional settings tab and click on Run preview in the Time to Live (TTL) section.
- Put the same attribute value which you did in the previous step, i.e.
expire_at. - In the Simulated date and time put the same or greater value of epoch time.
- Click Run preview
You will see your item in the able below.

After few minutes, if you go to the table and query for that item, it should no longer be there.
What is the DynamoDB TTL cost?
TTL has no additional cost. Thanks to AWS.
Is DynamoDB TTL reliable?
How accurate is DynamoDB TTL really?
Since the timestamp for TTL is stored in UNIX epoch time, it can only provide you granularity up to seconds, not milliseconds.
What about the accuracy of deletion?
The item doesn’t get deleted at the exact time. It gets deleted within a couple of hours in most cases, but it can take up to 48 hours.
Tip
If your DynamoDB TTL is not working, you should just wait for a while.
Is there any limit to DynamoDB TTL?
No there is no upper limit for DynamoDB TTL. You can set TTL of even more than 5 years.
How to trigger Lambda with DynamoDB TTL
- Go to your DynamoDB table settings and select Exports and streams tab
- In the DynamoDB stream details section click Turn on
- Now select Old image in the View type
- Click Turn on stream
Now you will receive updates for all the deleted items in Lambda function.

Setup Lambda to capture the deleted items
You will need to create a Lambda function and add DynamoDB stream as event source.
Learn how to configure the Lambda to use this DynamoDB stream.
DynamoDB TTL alternatives
The best alternative right now is Amazon EventBridge Scheduler.

You can create a one-time or repeating schedule which will trigger a Lambda function which can delete item(s) based on the specified time or whenever the schedule is triggered.