Bird
Raised Fist0
DynamoDBquery~10 mins

TTL use cases (sessions, logs, cache) in DynamoDB - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the TTL attribute name for a DynamoDB table.

DynamoDB
aws dynamodb update-time-to-live --table-name UserSessions --time-to-live-specification Enabled=true, AttributeName=[1]
Drag options to blanks, or click blank then click option'
AExpirationTime
BTTL
CDeleteAt
DExpireAt
Attempts:
3 left
💡 Hint
Common Mistakes
Using attribute names that are not configured as TTL attribute in the table.
Confusing TTL attribute name with other attribute names.
2fill in blank
medium

Complete the code to insert a session item with TTL set to expire in 1 hour.

DynamoDB
aws dynamodb put-item --table-name UserSessions --item '{"SessionId": {"S": "abc123"}, "UserId": {"S": "user1"}, "TTL": {"N": "[1]"}}'
Drag options to blanks, or click blank then click option'
A1672531200
B1672527600
C1672534800
D1672538400
Attempts:
3 left
💡 Hint
Common Mistakes
Using TTL as a date string instead of Unix timestamp.
Setting TTL to a past timestamp.
3fill in blank
hard

Fix the error in the TTL attribute type for a log entry.

DynamoDB
aws dynamodb put-item --table-name Logs --item '{"LogId": {"S": "log001"}, "Message": {"S": "Error occurred"}, "TTL": {"[1]": "1672534800"}}'
Drag options to blanks, or click blank then click option'
AN
BS
CBOOL
DM
Attempts:
3 left
💡 Hint
Common Mistakes
Using string type for TTL value.
Using boolean or map types for TTL.
4fill in blank
hard

Fill both blanks to create a cache item with TTL set to expire after 10 minutes.

DynamoDB
aws dynamodb put-item --table-name Cache --item '{"CacheKey": {"S": "user_profile_123"}, "Data": {"S": "[1]"}, "TTL": {"N": "[2]"}}'
Drag options to blanks, or click blank then click option'
A{"name":"John"}
B1672535400
C1672534800
D{"name":"Jane"}
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect TTL timestamp.
Using invalid JSON string for cache data.
5fill in blank
hard

Fill all three blanks to query expired sessions and delete them.

DynamoDB
aws dynamodb scan --table-name UserSessions --filter-expression "[1] < :now" --expression-attribute-values '{":now": {"[2]": "[3]"}}'
Drag options to blanks, or click blank then click option'
ATTL
BN
C1672534800
DS
Attempts:
3 left
💡 Hint
Common Mistakes
Using string type for timestamp in expression attribute values.
Filtering on wrong attribute name.

Practice

(1/5)
1. What is the main purpose of TTL (Time To Live) in DynamoDB?
easy
A. Automatically delete items after a specified time to save storage
B. Encrypt data for security
C. Backup data to another region
D. Increase read capacity automatically

Solution

  1. Step 1: Understand TTL functionality

    TTL marks items with an expiration timestamp to delete them automatically after that time.
  2. Step 2: Identify the main benefit

    This automatic deletion helps save storage and keeps data fresh without manual cleanup.
  3. Final Answer:

    Automatically delete items after a specified time to save storage -> Option A
  4. Quick Check:

    TTL = automatic deletion [OK]
Hint: TTL deletes expired data automatically to save space [OK]
Common Mistakes:
  • Confusing TTL with encryption
  • Thinking TTL backs up data
  • Assuming TTL changes capacity settings
2. Which attribute type must the TTL attribute have in a DynamoDB table?
easy
A. String representing a date
B. Boolean indicating expiration
C. Binary data
D. Number representing epoch time in seconds

Solution

  1. Step 1: Check TTL attribute requirements

    DynamoDB TTL requires a Number attribute that stores the expiration time as epoch time in seconds.
  2. Step 2: Eliminate other types

    String, Boolean, or Binary types are not valid for TTL expiration timestamps.
  3. Final Answer:

    Number representing epoch time in seconds -> Option D
  4. Quick Check:

    TTL attribute = epoch seconds number [OK]
Hint: TTL attribute must be a number with epoch seconds [OK]
Common Mistakes:
  • Using string dates instead of numbers
  • Setting TTL attribute as Boolean
  • Using binary data for TTL
3. Given a DynamoDB table with TTL enabled on attribute expireAt, what happens to an item with expireAt set to a timestamp 10 minutes in the past?
medium
A. The item is automatically deleted by DynamoDB
B. The item remains until manually deleted
C. The item is archived automatically
D. The item is updated with a new timestamp

Solution

  1. Step 1: Understand TTL expiration behavior

    Items with TTL timestamps in the past are marked for deletion by DynamoDB automatically.
  2. Step 2: Confirm deletion timing

    DynamoDB deletes expired items typically within 48 hours after expiration, often sooner.
  3. Final Answer:

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

    Expired TTL item = auto delete [OK]
Hint: Expired TTL items get deleted automatically [OK]
Common Mistakes:
  • Thinking expired items stay forever
  • Assuming items get archived
  • Believing TTL updates timestamps automatically
4. You enabled TTL on attribute sessionExpiry but items are not being deleted after expiration. What is the most likely cause?
medium
A. TTL only works on string attributes
B. The table has no primary key defined
C. The sessionExpiry attribute is missing or not a number
D. DynamoDB does not support TTL

Solution

  1. Step 1: Check TTL attribute correctness

    TTL requires the attribute to exist and be a number representing epoch time; missing or wrong type prevents deletion.
  2. Step 2: Verify other options

    Tables must have primary keys, but that doesn't affect TTL. TTL does not work on strings. DynamoDB supports TTL.
  3. Final Answer:

    The sessionExpiry attribute is missing or not a number -> Option C
  4. Quick Check:

    TTL attribute missing or wrong type = no deletion [OK]
Hint: TTL attribute must exist and be a number [OK]
Common Mistakes:
  • Assuming TTL works on strings
  • Ignoring missing TTL attribute
  • Thinking DynamoDB lacks TTL support
5. You want to use TTL to automatically expire cached items after 1 hour. Which approach correctly sets the TTL attribute cacheExpire when inserting an item?
hard
A. Set cacheExpire to current date string plus 1 hour
B. Set cacheExpire to current epoch time plus 3600 seconds
C. Set cacheExpire to Boolean true
D. Do not set cacheExpire attribute

Solution

  1. Step 1: Calculate TTL expiration timestamp

    TTL requires a number representing epoch time in seconds, so add 3600 seconds (1 hour) to current epoch time.
  2. Step 2: Confirm correct attribute setting

    Setting a string or Boolean won't work; omitting the attribute disables TTL for that item.
  3. Final Answer:

    Set cacheExpire to current epoch time plus 3600 seconds -> Option B
  4. Quick Check:

    TTL = current time + seconds [OK]
Hint: TTL value = current epoch seconds + expiration seconds [OK]
Common Mistakes:
  • Using date strings instead of epoch seconds
  • Setting TTL as Boolean
  • Not setting TTL attribute at all
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