AWS Lambda functions now can be built with Microsoft’s .NET 6, the latest major version of the software development platform. The introduction of the .NET 6 runtime for AWS Lambda enables new .NET Lambda capabilities that improve performance and diagnostics and support new coding patterns.
The .NET 6 Lambda runtime was introduced by AWS on February 24. Among the new capablities enabled is improved logging, with better traceability and control of what is being logged. The .NET 6 Lambda runtime allows the Lambda request ID to be added to logs, similar to other AWS Lambda runtimes. Also, several new logging APIs are available including LogCritical, LogError, and LogTrace. Developers still can use the style of logging from previous .NET managed runtimes if they prefer.
The .NET 6 Lambda runtime supports writing Lambda functions using C# 9 top-level statements, which allow developers to delete much of the initial boilerplate code for a .NET project. Microsoft .NET 6 introduced a new style of writing ASP.NET Core applications, called Minimal APIs, which take advantage of C# 9 top-level statements to simplify the initialization of an application. Developers can define an entire application in a single file. Microsoft .NET 6 also introduced the C# 10 and F# 6 languages.
AWS Lambda is Amazon Web Services’ popular event-driven, serverless computing platform. Developers can create an AWS account at portal.aws.amazon.com. To migrate existing .NET Lamdba functions to .NET 6, developers can do the following:
- Open the csproj or fsproj file. Set the
TargetFramework
element tonet6.0
. - If it exists, open the aws-lambda-tools-defaults.json file.
- Set the
function-runtime
field todotnet6
. - Set the
framework
field tonet6.0
. If you remove the field, the value is inferred from the project file. - If it exists, open the serverless.template file. For any
AWS::Lambda::Function
orAWS::Servereless::Function
resource, set theRuntime
property todotnet6
. - Update all
Amazon.Lambda.*
NuGet package references to the latest versions.
With .NET and AWS Lambda, developers can use the tool of their choice, including the Microsoft Visual Studio 2022 IDE, with the AWS Toolkit for Visual Studio, the .NET CLI with Amazon Lambda Tools, and the AWS Serverless Application Model CLI (AWS SAM CLI). The .NET 6 Lambda managed runtime supports x86 and Arm/Graviton processors.