how does TypeDeserialization work with DynamoDBStreamEvent #976
-
Trying to de-serialize dynamodb stream event in lambda, when using the below, number types get transformed to string # event: DynamoDBStreamEvent
for record in event.records:
if record.event_name == DynamoDBRecordEventName.REMOVE:
output = {k: v.get_value for k, v in data.items()} so tried using type deserializer from boto3, but below didn't work as v is a object and not a dict from boto3.dynamodb.types import TypeDeserializer
deserializer = TypeDeserializer()
# event: DynamoDBStreamEvent
for record in event.records:
if record.event_name == DynamoDBRecordEventName.REMOVE:
output = {k: deserializer.deserialize(v) for k, v in data.items()}
# ERROR - AttributeError: 'AttributeValue' object has no attribute 'keys' What worked - was passing the from boto3.dynamodb.types import TypeDeserializer
deserializer = TypeDeserializer()
# event: DynamoDBStreamEvent
for record in event.records:
if record.event_name == DynamoDBRecordEventName.REMOVE:
output = {k: deserializer.deserialize(v._data) for k, v in data.items()} Is there a way to derserialize the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@Muthuveerappanv would it be possible to post a more complete example with an event, so i can reproduce your issue and see if we can make a fix for it or use the existing api to do what you want. Otherwise |
Beta Was this translation helpful? Give feedback.
-
**See if this helps. ☝🏻 ** from_dict = {k: deserializer.deserialize(v) for k, v in record.dynamodb._data["OldImage"].items()}
print("Works with Dict", from_dict) |
Beta Was this translation helpful? Give feedback.
ddb_stream_deserialize.zip
**See if this helps. ☝🏻 **
get_value
helps get value of individual attribute. What if I want to transform the entire record.As highlighted in the example, getting the _data from the object, helps get the dict and from there the deserializer can work, but i wanted to check if that was the intended way from a powertools data model perspective