aws-lambda-dotnet icon indicating copy to clipboard operation
aws-lambda-dotnet copied to clipboard

Allow AspNetCoreServer.Hosting to use a custom serializer

Open jeastham1993 opened this issue 3 years ago • 3 comments

Describe the feature

Currently the AspNetCoreServer.Hosting package initializes a DefaultLambdaJsonSerializer when creating the HandlerWrapper for the specific RuntimeSupportServer. Update this to use DefaultLamddaJsonSerializer as a default but allow a custom JsonSerializer to be used if required.

A link to the line in question can be seen here: https://github.com/aws/aws-lambda-dotnet/blob/0e8e42a0fe818f1adc1f97bb035f2535934c16b4/Libraries/src/Amazon.Lambda.AspNetCoreServer.Hosting/Internal/LambdaRuntimeSupportServer.cs#L73

Use Case

Allow source generated serialization to be used when running an API on Lambda. If compiling an API with NativeAOT enabled to run on Lambda the DefaultLambdaJsonSerializer will not work and a custom serialization context is required.

Proposed Solution

Add an optional parameter to the AddAWSLambdaHosting method to allow a custom serializer to be passed in. Store the option in a static variable.

Update the CreateHandlerWrapper method to use this static variable instead of being hardcoded to initialize a new DefaultLambdaJsonSerializer.

Other Information

No response

Acknowledgements

  • [X] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

AWS .NET SDK and/or Package version used

Amazon.Lambda.AspNetCoreServer.Hosting 1.0.0

Targeted .NET Platform

.NET6 / .NET 7

Operating System and version

ASL2

jeastham1993 avatar Sep 03 '22 14:09 jeastham1993

This needs review with the team. @jeastham1993 Feel free to contribute PR so that it could be reviewed by the team.

ashishdhingra avatar Sep 12 '22 23:09 ashishdhingra

@ashishdhingra happy to. I've got a version I've been using for testing locally. I'll create a PR today or tomorrow for review.

jeastham1993 avatar Sep 13 '22 14:09 jeastham1993

@ashishdhingra PR raised.

jeastham1993 avatar Sep 15 '22 06:09 jeastham1993

PR has been released as part of version 1.5.0 of Amazon.Lambda.AspNetCoreServer.Hosting

normj avatar Dec 09 '22 08:12 normj

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Dec 09 '22 08:12 github-actions[bot]