Complete the code to enable TTL on the DynamoDB table.
aws dynamodb update-time-to-live --table-name MyTable --time-to-live-specification Enabled=[1], AttributeName=expiryDateTTL is enabled by setting Enabled=true in the specification.
Complete the code to create a DynamoDB stream for archival.
aws dynamodb update-table --table-name MyTable --stream-specification StreamEnabled=[1], StreamViewType=OLD_IMAGETo enable streams, StreamEnabled must be set to lowercase true.
Fix the error in the Lambda function event handler to process DynamoDB stream records.
def lambda_handler(event, context): for record in event['Records']: if record['eventName'] == '[1]': print('Archiving expired item')
The event name for expired items removed by TTL is REMOVE.
Fill in the blank to extract the expired item and archive it.
def lambda_handler(event, context): for record in event['Records']: if record['eventName'] == 'REMOVE': key = record['dynamodb']['[1]'] archive_table.put_item(Item=key)
The expired item's data is in OldImage for archiving to the archive table.
Fill all three blanks to filter expired items and log their IDs.
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}")
Expired items trigger REMOVE events, data is in OldImage, and the ID attribute is usually named 'id'.
