-
Notifications
You must be signed in to change notification settings - Fork 475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to convert DynamoDBEvent images to DynamoDBv2.Document #1657
Comments
We've just hit this as well. We can no longer do
I can understand wanting to break the dependency but its weird to have AttributeValue duplicated as different classes across the two libraries, is the plan to have it live in a shared model library? |
We've released version 3.1.0 of Amazon.Lambda.DynamoDBEvents, which adds a We still kept the event definition separate from the SDK definition in AWSSDK.DynamoDBv2, which we split in version 3.0.0 via #1648. This avoids some interaction with code relevant to the SDK but not to Lambda (request marshallers), and may reduce the package size for cases where one only needs to read the event without using the full DynamoDB SDK. You can now use the
Note that the JSON conversion has the same limitations as the SDK: the sets (SS, NS, BS) will be converted to JSON arrays, and binary (B) will be converted to Base64 strings
I think that will address both use cases reported above, but let us know if you're still seeing limitations after 3.1.0. Thanks. |
@ashovlin Thanks, everything worked great! However, we have a scenario (testing) where we are building a DynamoDB stream event based of an object - see code
Now I want to return an Dictionary<string, DynamoDBEvent.AttributeValue, but not really sure how I would go about it now that ToAttributeMap() returns a different AttributeValue. What's the best approach here? |
The only thing we spotted so far is that one of our unit tests shows I think this might be caused by the
This was actually a 'bug' in our unit test where we were setting up an AttributeValue in an image Dictionary incorrectly as So like:
See https://dotnetfiddle.net/Fomy9m So reporting as this was a change in behaviour for us versus |
|
@adam-knights - we just released Amazon.Lambda.DynamoDBEvents v3.1.1, which should handle the "empty" case for |
@ashovlin - Do you have any update regarding the first point? |
Any workaround using AWSSDK.DynamoDBv2 would be fine, e.g. JSON -> DynamoDBv2.Document -> Dictionary<string, DynamoDBEvent.AttributeValue>. I've tried to get a "DynamoDB" JSON from Document, so I could deserialize it to Dictionary<string, DynamoDBEvent.AttributeValue>. Unfortunately, I haven't found an easy way to do that. |
@psdanielhosseini / @Dreamescaper - I separated this request over to #1700. I'll leave this issue #1657 focused on going from the 3.0.0+ |
Hello @ashovlin, I'm looking for a way of converting Dictionary<string, Amazon.Lambda.DynamoDBEvents.DynamoDBEvent.AttributeValue> to Dictionary<string, Amazon.DynamoDBv2.Model.AttributeValue> or Amazon.Lambda.DynamoDBEvents.DynamoDBEvent.AttributeValue to Amazon.DynamoDBv2.Model.AttributeValue at least. Do you provide an "out of the box" solution? I could see something similar in Kind regards |
I have just run into this issue with mapping from DynamoDBEvent models as well. In my case I am mapping the new image to an object persistence class that has a property using an IPropertyConverter to store the value in a binary field with gzip compression. The ToJson() method doesn't work because that will convert the binary property into a string. The string is base 64 encoded and contains a byte order mark that the converter does not normally encounter. DynamoDBEntry doesn't seem to have any method for exposing the attribute type either. AsByteArray or AsMemoryStream throw InvalidOperationException if the conversion is not supported. |
Any update on this? An implementation of ToAttributeMap() is all I need to be able to update to the newest version |
@starkcolin I was stuck with the same issue and got around it for now by creating extension methods for mapping from the lambda dynamodb event type to the model type. This seems to work but it would be nice for this to be something built into the nuget package for mapping from x to y and back. Hope some of this helps someone else.
|
All these options depend on the Context. Is there a plan to add support for a deserializer which doesn't use the context? |
To convert from event to document the suggested:
does not really work (?) - for example if NewImage contains a binary attribute the resulting JSON is
that gets converted to a document that has that attribute as a string, not binary Also going from a dictionary to a JSON string and then parse that seems pretty inefficient? Using DynamoDBEvents 3.1.1 |
Discussed in #1654
Originally posted by Dreamescaper January 16, 2024
I have a lambda subscribed to dynamoDb events. I want to convert event's records to regular JSON, currently we use something like that:
However, it doesn't work after the #1648 is merged.
Could anyone suggest what is the easiest way to do same after the update?
The text was updated successfully, but these errors were encountered: