From 3d226c5b4c2b83fc53825c1564c822da047f376b Mon Sep 17 00:00:00 2001 From: Peter Gaultney Date: Fri, 15 Jan 2021 11:25:15 -0600 Subject: [PATCH] enhance watch_ddb_stream script --- dev-utils/watch_ddb_stream.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/dev-utils/watch_ddb_stream.py b/dev-utils/watch_ddb_stream.py index bd3b95e..b3a1912 100755 --- a/dev-utils/watch_ddb_stream.py +++ b/dev-utils/watch_ddb_stream.py @@ -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") @@ -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 @@ -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: