Bird
Raised Fist0
DynamoDBquery~20 mins

TTL attribute setup in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
TTL Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:00remaining
Understanding TTL attribute purpose
What is the main purpose of setting a TTL (Time To Live) attribute on a DynamoDB table item?
ATo automatically delete items after a specified time to reduce storage costs
BTo encrypt the item data for security purposes
CTo create a backup of the item before deletion
DTo increase the read capacity of the table temporarily
Attempts:
2 left
💡 Hint
Think about why you would want items to disappear automatically.
❓ query_result
intermediate
1:00remaining
TTL attribute data type and value
Which of the following is the correct data type and value format for a TTL attribute in DynamoDB?
AA boolean value indicating if the item should expire
BA string representing a date in ISO 8601 format, e.g., "2024-06-01T12:00:00Z"
CA number representing the Unix epoch time in seconds when the item expires
DA map containing the expiration date and time
Attempts:
2 left
💡 Hint
TTL uses a timestamp in seconds since 1970-01-01.
📝 Syntax
advanced
1:30remaining
Enabling TTL on a DynamoDB table
Which AWS CLI command correctly enables TTL on a DynamoDB table with the TTL attribute named 'expireAt'?
Aaws dynamodb update-table --table-name MyTable --ttl Enabled expireAt
Baws dynamodb update-time-to-live --table-name MyTable --time-to-live-specification Enabled=true,AttributeName=expireAt
Caws dynamodb set-ttl --table-name MyTable --ttl-attribute expireAt --enable
Daws dynamodb enable-ttl --table MyTable --attribute expireAt
Attempts:
2 left
💡 Hint
Check the official AWS CLI command syntax for TTL update.
❓ optimization
advanced
1:30remaining
Optimizing TTL attribute usage
To optimize the TTL feature and avoid unexpected data retention, which practice is recommended when setting the TTL attribute value?
ASet the TTL attribute to the current time to delete items immediately
BDo not set the TTL attribute; rely on manual deletion instead
CSet the TTL attribute to a timestamp far in the past to trigger instant deletion
DSet the TTL attribute to a timestamp at least 24 hours in the future to allow for processing delays
Attempts:
2 left
💡 Hint
TTL deletion is not immediate; allow some buffer time.
🔧 Debug
expert
2:00remaining
Troubleshooting TTL not deleting expired items
You enabled TTL on your DynamoDB table with attribute 'expireAt', but expired items are not being deleted after several days. What is the most likely cause?
AThe TTL attribute values are stored as strings instead of numbers
BThe table's read capacity is too low to process TTL deletions
CThe TTL attribute name is misspelled in the update-time-to-live command
DDynamoDB does not support TTL on tables with global secondary indexes
Attempts:
2 left
💡 Hint
TTL attribute must be a number, not a string.

Practice

(1/5)
1. What is the main purpose of setting a TTL attribute in a DynamoDB table?
easy
A. To increase the read capacity of the table
B. To encrypt data stored in the table
C. To create backups of the table data
D. To automatically delete expired items based on a timestamp

Solution

  1. Step 1: Understand TTL functionality

    TTL (Time To Live) is used to automatically remove items after a certain time.
  2. Step 2: Identify the purpose in DynamoDB context

    In DynamoDB, TTL deletes expired items to save storage and cost.
  3. Final Answer:

    To automatically delete expired items based on a timestamp -> Option D
  4. Quick Check:

    TTL = auto-delete expired items [OK]
Hint: TTL means auto-delete expired data by timestamp [OK]
Common Mistakes:
  • Confusing TTL with encryption
  • Thinking TTL increases capacity
  • Assuming TTL creates backups
2. Which of the following is the correct way to specify the TTL attribute in DynamoDB?
easy
A. Set a numeric attribute with Unix epoch time in seconds
B. Set a list attribute with expiration dates
C. Set a boolean attribute to true when item expires
D. Set a string attribute with date format 'YYYY-MM-DD'

Solution

  1. Step 1: Recall TTL attribute data type

    DynamoDB TTL requires a numeric attribute representing Unix epoch time in seconds.
  2. Step 2: Evaluate options

    Only Set a numeric attribute with Unix epoch time in seconds correctly uses numeric Unix epoch seconds for TTL.
  3. Final Answer:

    Set a numeric attribute with Unix epoch time in seconds -> Option A
  4. Quick Check:

    TTL attribute = numeric Unix epoch seconds [OK]
Hint: TTL attribute must be numeric Unix epoch seconds [OK]
Common Mistakes:
  • Using string date formats instead of numeric
  • Using boolean or list types for TTL
  • Not enabling TTL on the table after setting attribute
3. Given a DynamoDB item with attribute expireAt set to 1700000000 (Unix epoch seconds), and TTL enabled on expireAt, what happens when the current time is 1700000001?
medium
A. The item remains until manually deleted
B. The item is automatically deleted by DynamoDB
C. The item is archived automatically
D. The item is updated with a new TTL value

Solution

  1. Step 1: Understand TTL expiration behavior

    When current time exceeds the TTL timestamp, DynamoDB marks the item for deletion.
  2. Step 2: Apply to given timestamp

    Since current time 1700000001 > expireAt 1700000000, item is deleted automatically.
  3. Final Answer:

    The item is automatically deleted by DynamoDB -> Option B
  4. Quick Check:

    Current time > TTL timestamp = item deleted [OK]
Hint: Item deletes when current time passes TTL timestamp [OK]
Common Mistakes:
  • Thinking item stays until manual deletion
  • Assuming item is archived instead of deleted
  • Believing TTL updates item automatically
4. You set the TTL attribute to a string value like "2024-12-31" and enabled TTL on that attribute. What issue will you face?
medium
A. TTL will not delete expired items because attribute is not numeric
B. DynamoDB will throw a syntax error on enabling TTL
C. Items will be deleted immediately regardless of date
D. TTL will convert string to numeric automatically

Solution

  1. Step 1: Check TTL attribute type requirement

    TTL attribute must be numeric Unix epoch seconds, not string.
  2. Step 2: Analyze effect of string value

    DynamoDB ignores TTL deletion if attribute is not numeric, so items won't expire.
  3. Final Answer:

    TTL will not delete expired items because attribute is not numeric -> Option A
  4. Quick Check:

    Non-numeric TTL attribute = no deletion [OK]
Hint: TTL attribute must be numeric; strings cause no deletion [OK]
Common Mistakes:
  • Expecting DynamoDB to error on TTL enable
  • Assuming immediate deletion with wrong type
  • Believing automatic type conversion happens
5. You want to set up TTL on a DynamoDB table to delete items 7 days after creation. Which approach correctly sets the TTL attribute expireAt when inserting an item?
hard
A. Set expireAt to a boolean true after 7 days
B. Set expireAt to current date string plus 7 days in 'YYYY-MM-DD' format
C. Set expireAt to current Unix epoch seconds plus 604800 (7 days in seconds)
D. Set expireAt to the current Unix epoch seconds without adding days

Solution

  1. Step 1: Calculate TTL timestamp for 7 days later

    7 days = 7 * 24 * 60 * 60 = 604800 seconds; add to current Unix epoch seconds.
  2. Step 2: Set TTL attribute correctly

    Assign expireAt the numeric value of current time + 604800 seconds for proper TTL.
  3. Final Answer:

    Set expireAt to current Unix epoch seconds plus 604800 (7 days in seconds) -> Option C
  4. Quick Check:

    TTL timestamp = now + 7 days in seconds [OK]
Hint: Add 604800 seconds to now for 7-day TTL [OK]
Common Mistakes:
  • Using date strings instead of numeric timestamps
  • Setting TTL to current time without delay
  • Using boolean or other types for TTL
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard