Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News .NET Lambda Annotations Framework Now Generally Available

.NET Lambda Annotations Framework Now Generally Available

.NET Lambda Annotations Framework is now generally available. Last year this framework was introduced in the preview version. It simplifies AWS Lambda development for .NET developers using custom attributes and source generators, allowing easy translation into standard Lambda programming during compilation. Moreover, it supports Dependency Injection and CloudFormation integration, improving Lambda function creation and deployment in AWS.

The .NET Lambda Annotations Framework is a new approach for .NET developers to build AWS Lambda functions effortlessly. By leveraging custom C# attributes and source generators, the framework translates annotated Lambda functions into the standard Lambda programming model during compilation, leaving the Lambda runtime unaffected. No additional tools are needed except for the NuGet Annotations Lambda package, making it compatible with various Lambda deployment tools utilizing CloudFormation. This includes AWS Toolkit for Visual Studio, Lambda .NET CLI, or SAM. With this natural programming model, developers can streamline Lambda function creation and deployment in AWS, boosting development productivity significantly.

In order to get started with the .NET Lambda Framework, the following things must be installed and configured: Visual Studio 2022, the latest version of AWS Toolkit for Visual Studio, an IAM user with the appropriate permissions to develop APIs using the Amazon API Gateway pods, AWS Lambda Functions, and Amazon Simple Storage Service. If an IDE other than Visual Studio is used, the same project template can be created from the Amazon.Lambda.Templates NuGet package:

dotnet new install Amazon.Lambda.Templates
dotnet new serverless.Annotations --output LambdaAnnotations

Lambda function using the Lambda Annotations Framework (Source: AWS Developer Tools Blog)

The created project from a template contains a collection of Lambda functions, defined in the Function.cs file. The LambdaFunction attribute designates the C# method as a Lambda function, synced with the CloudFormation template. Moreover, the HttpApi attribute incorporates the API Gateway event configuration into the CloudFormation template. This integration ensures smooth deployment and synchronization of Lambda functions with the API Gateway, all orchestrated through the CloudFormation infrastructure.

The project contains a serverless.template file that serves as a CloudFormation template for implementing Lambda functions. When a C# language method is tagged with the LambdaFunction attribute, it dynamically creates a matching declaration in the template. 

The .NET community is wondering about the usage of this solution. A Reddit user left a question/insight:

Tempted to try this, but cold starts are a big pain point already with .Net Lambda, and splitting an API into a Lambda per endpoint would only exacerbate this?

More details about .NET Lambda Annotations Framework can be found on the GitHub page or Developer Documentation.

About the Author

Rate this Article