For those of us that are .NET developers at heart, we have powerful tools for running serverless C# applications on AWS. AWS Lambda now officially supports .NET 10 as a managed runtime, providing long-term support (LTS) through November 2028.
Modern C# support in Lambda has evolved beyond early .NET Core. Developers can now utilize C# File-Based apps, which eliminate much of the traditional boilerplate code. These functions typically publish as Native AOT (Ahead-of-Time) by default, offering up to an 86% improvement in cold start times by removing the need for JIT compilation at runtime.
Prerequisites:
- Development Environment: Visual Studio 2022 (latest version) with the .NET 10 SDK installed.
- AWS Toolkit for Visual Studio: Install the latest extension from the Visual Studio Marketplace. It now includes Amazon Q Developer for AI-assisted coding and one-click publishing.
Getting Started with the .NET CLI:
The fastest way to scaffold a new function is using the Amazon Lambda Templates. You can install and create a file-based function with these commands:
dotnet new install Amazon.Lambda.Templates
dotnet new lambda.FileBased -n MyLambdaFunction
Key Project References:
- Amazon.Lambda.Core: The foundational library for Lambda functions.
- Amazon.Lambda.RuntimeSupport: Required for file-based apps and Native AOT.
- Amazon.Lambda.Serialization.SystemTextJson: High-performance JSON serialization using source generators.
Using the AWS Toolkit, you can right-click your project and select "Publish to AWS Lambda" to deploy instantly. The toolkit handles the complexity of Native AOT container builds automatically if Docker is installed on your machine.