KKeySync
← Back to quests
Quest · quest 15Johto · Advanced

Burn Heal (Time to Live)

Your Pokémon gets "Burned" in battle. Instead of manually writing a cron job to remove the "Burned" status effect after 5 minutes, we can use DynamoDB Time To Live (TTL).

TTLAsynchronous deletionRead filtering

Key takeaways

  • TTL marks items for asynchronous background deletion; expiration is not immediate.
  • The TTL attribute must be a Number type representing Epoch Seconds.
  • Expired items can remain visible for days, so application reads should filter them out.

Burn Heal (TTL)

Add an ExpirationTime attribute and enable that exact attribute as the table's TTL setting. Once the timestamp passes, the item becomes eligible for background deletion. Until DynamoDB removes it, your application must treat it as expired.

Writing an item with TTLjavascript

Interactive Challenge

A Burn should clear itself after 5 minutes. Add an ExpirationTime TTL attribute (epoch seconds) so DynamoDB can remove it asynchronously. Treat expired items as invalid in application reads until background deletion finishes.

Goal: Add ExpirationTime: Math.floor(Date.now() / 1000) + 300 to the item.

Quick Quiz

What format must the TTL attribute be in for DynamoDB to automatically delete the item?

Make your choice to test your understanding. Submit to check, and if it's not quite right you can adjust and try again.