0
0
DynamoDBquery~10 mins

TTL with Streams for archival in DynamoDB - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - TTL with Streams for archival
Item inserted in DynamoDB table
TTL attribute set with expiry timestamp
Time passes until TTL expires
DynamoDB deletes expired item
Stream captures deletion event
Lambda triggered by Stream event
Lambda archives deleted item to S3 or another store
This flow shows how DynamoDB TTL deletes expired items, streams capture the deletion, and a Lambda archives the deleted data.
Execution Sample
DynamoDB
1. Insert item with TTL attribute (expiry timestamp)
2. Wait until TTL expires
3. DynamoDB deletes item
4. Stream records deletion event
5. Lambda triggered by stream
6. Lambda archives item
This sequence shows how an item with TTL is deleted and archived via DynamoDB Streams and Lambda.
Execution Table
StepActionTTL AttributeStream EventLambda TriggeredArchive Action
1Insert itemTTL set to future timestampNoNoNo
2Wait for TTL expiryTTL timestamp reachedNoNoNo
3DynamoDB deletes expired itemExpiredDeletion event generatedNoNo
4Stream sends deletion eventExpiredDeletion event presentNoNo
5Lambda triggered by streamExpiredDeletion event presentYesStarted archiving
6Lambda archives itemExpiredDeletion event presentYesItem archived
7Process completeExpiredDeletion event processedNoArchive done
💡 Process stops after Lambda archives the deleted item from the stream event.
Variable Tracker
VariableStartAfter Step 1After Step 3After Step 5Final
Item TTLNoneFuture timestamp setExpiredExpiredExpired
Stream EventNoneNoneDeletion event generatedDeletion event presentProcessed
Lambda TriggeredNoNoNoYesNo
Archive StatusNot startedNot startedNot startedStartedDone
Key Moments - 3 Insights
Why doesn't the Lambda trigger immediately after setting the TTL attribute?
Because TTL expiry happens asynchronously after the timestamp passes, so the stream deletion event only appears after DynamoDB deletes the expired item (see execution_table step 3 and 4).
What does the stream capture when an item expires?
The stream captures a deletion event for the expired item, which triggers the Lambda to archive it (see execution_table step 4).
Can the Lambda archive the item before the TTL expiry?
No, the Lambda only triggers after the deletion event from the stream, which happens after TTL expiry and item deletion (see execution_table steps 3 to 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the Lambda first get triggered?
AStep 3
BStep 4
CStep 5
DStep 6
💡 Hint
Check the 'Lambda Triggered' column in execution_table rows.
According to variable_tracker, what is the Archive Status after Step 5?
ANot started
BStarted
CDone
DFailed
💡 Hint
Look at the 'Archive Status' row and the 'After Step 5' column.
If the TTL attribute is never set, what happens to the stream event?
ANo deletion event is generated
BLambda triggers without event
CDeletion event is generated anyway
DItem is archived immediately
💡 Hint
Refer to the flow where TTL expiry causes deletion and stream event.
Concept Snapshot
DynamoDB TTL deletes expired items automatically.
Deletion triggers a stream event.
Lambda listens to stream events.
Lambda archives deleted items.
This automates archival after TTL expiry.
Full Transcript
This visual execution shows how DynamoDB TTL works with Streams for archival. First, an item is inserted with a TTL attribute set to a future timestamp. Time passes until the TTL expires. DynamoDB then deletes the expired item. This deletion generates a stream event. The stream event triggers a Lambda function. The Lambda archives the deleted item to an external store like S3. Variables like TTL attribute, stream event presence, Lambda trigger, and archive status change step-by-step. Key moments clarify that Lambda triggers only after deletion, and the stream captures deletion events only after TTL expiry. The quiz tests understanding of when Lambda triggers, archive status progression, and what happens if TTL is not set.