Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using capitalized True instead of lowercase true.
Setting Enabled to false disables TTL.
✗ Incorrect
TTL is enabled by setting Enabled=true in the specification.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using capitalized True or False.
Setting StreamEnabled to false disables the stream.
✗ Incorrect
To enable streams, StreamEnabled must be set to lowercase true.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using DELETE instead of REMOVE.
Using non-existent event names like REMOVE_ITEM.
✗ Incorrect
The event name for expired items removed by TTL is REMOVE.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Keys instead of OldImage.
Using PartitionKey which is not a stream attribute.
✗ Incorrect
The expired item's data is in OldImage for archiving to the archive table.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using NewImage instead of OldImage.
Using wrong event name like INSERT.
✗ Incorrect
Expired items trigger REMOVE events, data is in OldImage, and the ID attribute is usually named 'id'.