Skip to content

Commit

Permalink
enhance watch_ddb_stream script
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Gaultney committed Jan 15, 2021
1 parent 9de1a2d commit 3d226c5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions dev-utils/watch_ddb_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
By default only prints the primary key.
"""
from typing import Callable
import argparse
from typing import Callable

import boto3

from xoto3.dynamodb.streams.records import old_and_new_items_from_stream_event_record
from xoto3.dynamodb.streams.consume import process_latest_from_stream
from xoto3.dynamodb.streams.records import old_and_new_items_from_stream_event_record
from xoto3.dynamodb.utils.index import hash_key_name, range_key_name


DDB_RES = boto3.resource("dynamodb")

DDB_STREAMS_CLIENT = boto3.client("dynamodbstreams")
Expand All @@ -25,7 +25,7 @@ def accept_stream_item(record: dict):
elif not new:
print(f"Deleted item {item_slicer(old)}")
else:
print(f"Updated item {item_slicer(new)}")
print(f"Updated item; OLD: {item_slicer(old)} NEW: {item_slicer(new)}")

return accept_stream_item

Expand Down Expand Up @@ -63,7 +63,11 @@ def main():
def item_slicer(item: dict):
return {
**key_slicer(item),
**{attr_name: item.get(attr_name) for attr_name in args.attribute_names},
**{
attr_name: item[attr_name]
for attr_name in args.attribute_names
if attr_name in item
},
}

else:
Expand Down

0 comments on commit 3d226c5

Please sign in to comment.