0
0
DynamoDBquery~10 mins

TTL with Streams for archival in DynamoDB - Interactive Code Practice

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

Complete the code to enable TTL on the DynamoDB table.

DynamoDB
aws dynamodb update-time-to-live --table-name MyTable --time-to-live-specification Enabled=[1], AttributeName=expiryDate
Drag options to blanks, or click blank then click option'
ATrue
Btrue
Cenabled
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using capitalized True instead of lowercase true.
Setting Enabled to false disables TTL.
2fill in blank
medium

Complete the code to create a DynamoDB stream for archival.

DynamoDB
aws dynamodb update-table --table-name MyTable --stream-specification StreamEnabled=[1], StreamViewType=OLD_IMAGE
Drag options to blanks, or click blank then click option'
AFalse
Bfalse
CTrue
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using capitalized True or False.
Setting StreamEnabled to false disables the stream.
3fill in blank
hard

Fix the error in the Lambda function event handler to process DynamoDB stream records.

DynamoDB
def lambda_handler(event, context):
    for record in event['Records']:
        if record['eventName'] == '[1]':
            print('Archiving expired item')
Drag options to blanks, or click blank then click option'
AREMOVE
BDELETE
CREMOVE_ITEM
DREMOVE_RECORD
Attempts:
3 left
💡 Hint
Common Mistakes
Using DELETE instead of REMOVE.
Using non-existent event names like REMOVE_ITEM.
4fill in blank
hard

Fill in the blank to extract the expired item and archive it.

DynamoDB
def lambda_handler(event, context):
    for record in event['Records']:
        if record['eventName'] == 'REMOVE':
            key = record['dynamodb']['[1]']
            archive_table.put_item(Item=key)
Drag options to blanks, or click blank then click option'
APartitionKey
BKeys
COldImage
DKey
Attempts:
3 left
💡 Hint
Common Mistakes
Using Keys instead of OldImage.
Using PartitionKey which is not a stream attribute.
5fill in blank
hard

Fill all three blanks to filter expired items and log their IDs.

DynamoDB
def lambda_handler(event, context):
    for record in event['Records']:
        if record['eventName'] == '[1]':
            expired_item = record['dynamodb']['[2]']
            item_id = expired_item['[3]']['S']
            print(f"Expired item ID: {item_id}")
Drag options to blanks, or click blank then click option'
AREMOVE
BOldImage
Cid
DNewImage
Attempts:
3 left
💡 Hint
Common Mistakes
Using NewImage instead of OldImage.
Using wrong event name like INSERT.