Following the release of the.NET 6 managed Runtime for AWS Lambda (AWS), Amazon Web Services (AWS), has released a preview version of the.NET Annotations Lambda Framework.
The new Annotations framework was created to make it easier to write.NET Lambda function functions in a more idiomatic (natural to C# and.NET 6) manner. It also offers other benefits, such as synchronization with CloudFormation (an infrastructure automation platform template) associated with a project.
The net result is to simplify coding. AWS provides an example of how code in the normal Lambda model can be made simpler by removing Lambda function codes using two.NET attributes that annotation the code.
Source generators are a C# construct that bridges the gap between the Lambda Annotations programming structure and the more idiomatic programming model. Source generators allow C# developers to inspect user code and create new source files that can then be used during compilation. AWS explained at a high level that the new library uses.NET Source Generator support to translate from Lambda’s low-level, single-event object programming model to ASP.NET Core. F# coders will be excluded from the Annotations party because source generators are a C# feature.
AWS stated that after adding the attributes to your.NET program, the source generator will generate the translation codes between the two programming models. It will also sync the generated information, including a new function handler string, into the CloudFormation template. The source generator can be used in a transparent manner.
The Amazon.Lambda.Annotations NuGet package contains the .NET attributes used to annotate the code for Lambda, along with the C# source generator used to create the generated translation code. It has been downloaded over 221,000 times.
The preview offering currently supports Lambda functions that leverage REST APIs. However, AWS hopes to simplify other events sources such as DynamoDB and S3 in the future.
