Skip to content
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

Add ToJson for DynamoDBEvent #1685

Merged
merged 2 commits into from
Mar 4, 2024
Merged

Add ToJson for DynamoDBEvent #1685

merged 2 commits into from
Mar 4, 2024

Conversation

ashovlin
Copy link
Member

Issue #, if available: #1654, #1657, DOTNET-7345

Description of changes:

Before

In #1648, we removed the dependency on AWSSDK.DynamoDBv2 from Amazon.Lambda.DynamoDBEvents. This allowed us to address nullability issues related to the SDK's marshalling code, which is likely not relevant when working with a Lambda event.

However, if you were working with the SDK's higher level document or object persistence representation of the DynamoDB event, that code may no longer work since the AWSSDK.DynamoDBv2 dependency may no longer be present and we separated the previously shared types.

After

Now, you can convert either the OldImage or NewImage on each DynamoDB event record to json via the new ToJson or ToJsonPretty methods. This can be used with Document.FromJson in AWSSDK.DynamoDBv2 to initialize the higher-level programming models.

foreach (var record in dynamoEvent.Records)
{
    // Convert the event to a JSON string
    var json = record.Dynamodb.NewImage.ToJson();

    // Which you can convert to the mid-level document model
    var document = Document.FromJson(json);
    
    // And then to the high-level object model using an IDynamoDBContext
    var myClass = context.FromDocument<T>(document);
}

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ashovlin
Copy link
Member Author

ashovlin commented Mar 1, 2024

CI failure is unrelated to this change, see aws/aws-extensions-for-dotnet-cli#302

@dscpinheiro
Copy link
Contributor

Were you planning to update the package version (https://github.com/aws/aws-lambda-dotnet/blob/master/Libraries/src/Amazon.Lambda.DynamoDBEvents/Amazon.Lambda.DynamoDBEvents.csproj#L9) later?

I also think it'd be good to update the blueprints to use the new version, but I guess we'd need to coordinate that with the toolkit team.

Thanks again for taking a look.

@ashovlin
Copy link
Member Author

ashovlin commented Mar 1, 2024

Were you planning to update the package version (https://github.com/aws/aws-lambda-dotnet/blob/master/Libraries/src/Amazon.Lambda.DynamoDBEvents/Amazon.Lambda.DynamoDBEvents.csproj#L9) later?

I also think it'd be good to update the blueprints to use the new version, but I guess we'd need to coordinate that with the toolkit team.

Thanks again for taking a look.

Added the version bump for Amazon.Lambda.DynamoDBEvents. I think we'd have to bump the blueprints in a separate PR anyway since those have a package reference that isn't in NuGet yet. I'll add a note to our internal ticket for after this ships.

@ashovlin ashovlin merged commit 9a7443a into dev Mar 4, 2024
4 checks passed
@ashovlin ashovlin deleted the shovlia/ddbevent-tojson branch March 4, 2024 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants