Bird
Raised Fist0
DynamoDBquery~20 mins

TTL with Streams for archival in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
TTL Streams Archival Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
What happens when an item expires with TTL enabled in DynamoDB?

Consider a DynamoDB table with TTL enabled on the attribute expiryTimestamp. What is the expected behavior when an item's TTL expires?

AThe item is immediately deleted and a stream record of type REMOVE is generated.
BThe item remains in the table until manually deleted; no stream record is generated.
CThe item is archived automatically to S3 and removed from the table instantly.
DThe item is deleted asynchronously after expiration and a stream record of type REMOVE is generated.
Attempts:
2 left
💡 Hint

TTL deletion is not immediate but happens asynchronously by DynamoDB.

🧠 Conceptual
intermediate
1:30remaining
Why use DynamoDB Streams with TTL for archival?

What is the main reason to enable DynamoDB Streams when using TTL for archival purposes?

ATo speed up the TTL deletion process by triggering immediate deletes.
BTo capture expired item deletions so they can be archived elsewhere before removal.
CTo prevent expired items from being deleted automatically.
DTo automatically backup the entire table every time TTL deletes an item.
Attempts:
2 left
💡 Hint

Think about how you can keep a copy of deleted items.

📝 Syntax
advanced
1:00remaining
Which DynamoDB Stream event type corresponds to TTL deletion?

Given a DynamoDB Stream event record, which eventName indicates an item was deleted due to TTL expiration?

A"REMOVE"
B"INSERT"
C"MODIFY"
D"EXPIRE"
Attempts:
2 left
💡 Hint

TTL deletions remove items from the table.

🔧 Debug
advanced
2:30remaining
Why is no stream record generated for expired items?

You enabled TTL and DynamoDB Streams on your table, but you notice no REMOVE events appear in the stream when items expire. What could be the cause?

ATTL deletions happen asynchronously and may take up to 48 hours to process, so no immediate stream events appear.
BStreams do not capture TTL deletions by design.
CThe TTL attribute is not set as a Number type, so TTL is ignored and no deletions occur.
DThe stream is configured to capture only INSERT events, so REMOVE events are filtered out.
Attempts:
2 left
💡 Hint

TTL deletions are asynchronous and can take up to 48 hours to appear in streams.

❓ optimization
expert
3:00remaining
Best practice for archiving expired DynamoDB items using TTL and Streams

You want to archive expired items from a DynamoDB table to S3 using TTL and Streams. Which approach optimizes cost and reliability?

AEnable TTL and Streams, but archive items directly from the stream without batching or retries.
BDisable TTL, and use Streams to capture all INSERT and MODIFY events, then archive items after a fixed time.
CEnable TTL and Streams, use a Lambda triggered by REMOVE events to batch and write expired items to S3 asynchronously.
DEnable TTL only, and run a scheduled job to scan the table for expired items and archive them manually.
Attempts:
2 left
💡 Hint

Think about asynchronous processing and batching for cost efficiency.

Practice

(1/5)
1. What is the main purpose of enabling TTL (Time to Live) on a DynamoDB table?
easy
A. Increase read capacity units for faster queries
B. Encrypt data at rest for security
C. Create backups of the table automatically
D. Automatically delete expired items to keep the table clean

Solution

  1. Step 1: Understand TTL function

    TTL marks items with an expiration timestamp so DynamoDB can delete them automatically after expiry.
  2. Step 2: Identify TTL's main benefit

    This automatic deletion helps keep the table clean without manual intervention.
  3. Final Answer:

    Automatically delete expired items to keep the table clean -> Option D
  4. Quick Check:

    TTL = automatic deletion [OK]
Hint: TTL deletes expired data automatically [OK]
Common Mistakes:
  • Confusing TTL with encryption
  • Thinking TTL creates backups
  • Assuming TTL increases capacity
2. Which of the following is the correct way to enable TTL on a DynamoDB table using AWS CLI?
easy
A. aws dynamodb enable-ttl --table MyTable --attribute expiryDate
B. aws dynamodb set-ttl --table-name MyTable --ttl-attribute expiryDate
C. aws dynamodb update-time-to-live --table-name MyTable --time-to-live-specification Enabled=true,AttributeName=expiryDate
D. aws dynamodb activate-ttl --table MyTable --attributeName expiryDate

Solution

  1. Step 1: Recall AWS CLI TTL command

    The correct command is 'update-time-to-live' with parameters for table name and TTL specification.
  2. Step 2: Match correct syntax

    aws dynamodb update-time-to-live --table-name MyTable --time-to-live-specification Enabled=true,AttributeName=expiryDate uses the exact syntax: --time-to-live-specification Enabled=true,AttributeName=expiryDate.
  3. Final Answer:

    aws dynamodb update-time-to-live --table-name MyTable --time-to-live-specification Enabled=true,AttributeName=expiryDate -> Option C
  4. Quick Check:

    Correct CLI command = aws dynamodb update-time-to-live --table-name MyTable --time-to-live-specification Enabled=true,AttributeName=expiryDate [OK]
Hint: Use 'update-time-to-live' with Enabled=true [OK]
Common Mistakes:
  • Using non-existent commands like enable-ttl
  • Wrong parameter names
  • Missing 'time-to-live-specification' flag
3. Given a DynamoDB Stream enabled on a table with TTL, what type of event will appear in the stream when an item expires and is deleted?
medium
A. INSERT
B. REMOVE
C. MODIFY
D. UPDATE

Solution

  1. Step 1: Understand TTL deletion effect on streams

    When TTL deletes an item, DynamoDB Streams capture this as a REMOVE event because the item is removed.
  2. Step 2: Identify correct event type

    INSERT and MODIFY happen on new or updated items, not deletions. REMOVE is the correct event for deletions.
  3. Final Answer:

    REMOVE -> Option B
  4. Quick Check:

    TTL deletion = REMOVE event [OK]
Hint: TTL deletions trigger REMOVE events in streams [OK]
Common Mistakes:
  • Choosing INSERT or MODIFY for deletions
  • Confusing UPDATE with MODIFY
  • Assuming TTL triggers no stream events
4. You wrote a Lambda function triggered by DynamoDB Streams to archive deleted items. However, the Lambda never receives any events for expired items. What is the most likely cause?
medium
A. The stream is not enabled or not set to capture REMOVE events
B. TTL is not enabled on the table
C. Lambda function has no permissions to read the table
D. The table has no primary key defined

Solution

  1. Step 1: Check stream configuration

    If the Lambda never receives events, the stream might be disabled or not configured to capture REMOVE events, which TTL deletions generate.
  2. Step 2: Verify other causes

    TTL must be enabled, but if streams are off or missing REMOVE events, Lambda won't get notifications. Permissions or missing primary key would cause other errors.
  3. Final Answer:

    The stream is not enabled or not set to capture REMOVE events -> Option A
  4. Quick Check:

    Missing REMOVE events in stream = The stream is not enabled or not set to capture REMOVE events [OK]
Hint: Ensure stream captures REMOVE events for TTL deletions [OK]
Common Mistakes:
  • Ignoring stream settings
  • Assuming permissions cause no events
  • Overlooking TTL enablement
5. You want to archive expired DynamoDB items to S3 using a Lambda triggered by Streams. Which approach ensures no data loss and handles possible Lambda failures?
hard
A. Process REMOVE events in Lambda and write directly to S3, retrying on failure
B. Use TTL to delete items, ignore streams, and periodically scan table for expired items
C. Disable TTL and manually delete items after archiving
D. Process INSERT events in Lambda and archive items before expiration

Solution

  1. Step 1: Understand archival with TTL and streams

    TTL deletes expired items, streams capture REMOVE events. Lambda triggered by these events can archive data safely.
  2. Step 2: Ensure reliability and no data loss

    Processing REMOVE events and writing to S3 with retries ensures data is archived even if Lambda fails temporarily.
  3. Step 3: Evaluate other options

    Use TTL to delete items, ignore streams, and periodically scan table for expired items ignores streams and risks missing data. Disable TTL and manually delete items after archiving disables TTL, losing automatic cleanup. Process INSERT events in Lambda and archive items before expiration archives before expiration, which is not TTL-based archival.
  4. Final Answer:

    Process REMOVE events in Lambda and write directly to S3, retrying on failure -> Option A
  5. Quick Check:

    Reliable archival = Process REMOVE events in Lambda and write directly to S3, retrying on failure [OK]
Hint: Archive REMOVE events with retries for safety [OK]
Common Mistakes:
  • Ignoring stream REMOVE events
  • Disabling TTL unnecessarily
  • Archiving on INSERT instead of REMOVE
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