I am trying to run a .NET 6 Core Web API project in AWS Lambda like I can with a .NET Core 3.1 project
It looks like .NET 6 is not officially supported in Lambda but that running .NET 6 is possible by publishing the project in a specific way, specifying the use of a custom runtime for the function [provided.al2] and finally deploying to Lambda. I've followed tutorials such as the below and have been successful in running C# code with .NET 6 code in AWS Lambda.
However, when trying to deploy a full .NET 6 Web API project with the Serverless Framework and invoke it with a request via API Gateway I get the below error in Lambda. I've also installed the NuGet package: Amazon.Lambda.AspNetCoreServer.Hosting and registered it in Program.cs.
My assumption is that publishing method from these tutorials, where the project is self-contained, for linux-x64 would do the trick. It seems like this may be possible with a container image but I'm hoping to use the ZIP method of deploying for consistency with some of my older projects while we wait for native .NET 6 support.
https://nodogmablog.bryanhogan.net/2021/11/dotnet-6-custom-runtime-for-aws-lambda/ https://dev.to/memark/running-a-graphql-api-in-net-6-on-aws-lambda-17oc
The option for Lambda ASP.NET Core Web API from Amazon.Lambda.Templates results in a 3.1 app.
Since today (Feb 24, 2022) AWS Lambda supports .NET 6 as both a managed runtime and a container base image.
To build and deploy Lambda functions using .NET 6, use the .NET Core CLI, AWS Toolkit for Visual Studio, or AWS Serverless Application Model (AWS SAM). Additionally, you can also use the AWS-provided .NET 6 base image to build and deploy .NET 6 functions using a container image.
See the Announcement here
For more information on Lambda’s support for .NET 6, see the blog post at .NET 6 runtime now available in AWS Lambda.