简体   繁体   English

在 AWS Lambda 中运行 .NET 6 Web API 项目,部署为 ZIP

[英]Running .NET 6 Web API project in AWS Lambda with ZIP deployment

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我正在尝试在 AWS Lambda 中运行一个 .NET 6 Core Web API 项目,就像我可以使用 .NET Core 3.1 项目一样

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.看起来 .NET 6 并未在 Lambda 中得到官方支持,但可以通过以特定方式发布项目来运行 .NET 6,指定为 function [provided.al2] 使用自定义运行时并最终部署到 Lambda。我'我按照下面的教程成功地在 AWS Lambda 中运行 C# 代码和 .NET 6 代码。

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. 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并在 Program.cs 中注册。

My assumption is that publishing method from these tutorials, where the project is self-contained, for linux-x64 would do the trick.我的假设是这些教程中的发布方法,其中项目是独立的,对于 linux-x64 可以做到这一点。 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.这似乎可以通过容器映像实现,但我希望在等待本机 .NET 6 支持时使用 ZIP 部署方法与我的一些旧项目保持一致。

https://nodogmablog.bryanhogan.net/2021/11/do.net-6-custom-runtime-for-aws-lambda/ https://dev.to/memark/running-a-graphql-api-in.net-6-on-aws-lambda-17oc https://nodogmablog.bryanhogan.net/2021/11/do.net-6-custom-runtime-for-aws-lambda/ https://dev.to/memark/running-a-graphql-api-in。 net-6-on-aws-lambda-17oc

AWS Lambda 错误

The option for Lambda ASP.NET Core Web API from Amazon.Lambda.Templates results in a 3.1 app. Lambda ASP.NET Core Web API 来自 Amazon.Lambda.Templates 的选项导致 3.1 应用程序。

在此处输入图像描述

Since today (Feb 24, 2022) AWS Lambda supports .NET 6 as both a managed runtime and a container base image.从今天(2022 年 2 月 24 日)开始,AWS Lambda 支持 .NET 6 作为托管运行时和容器基础映像。

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).要使用 .NET 6 构建和部署 Lambda 函数,请使用 .NET 核心 CLI、AWS Toolkit for Visual Studio 或 AWS 无服务器应用程序 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.此外,您还可以使用 AWS 提供的 .NET 6 基础镜像,通过容器镜像构建和部署 .NET 6 函数。

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.有关 Lambda 对 .NET 6 的支持的更多信息,请参阅博客文章.NET 6 运行时现已在 AWS Lambda 中可用。

Edit 28/02/2022:编辑 28/02/2022:

Support for .NET 6 runtime for AWS Lambda is available now: Introducing the .NET 6 runtime for AWS Lambda Support for .NET 6 runtime for AWS Lambda is available now: Introducing the .NET 6 runtime for AWS Lambda


Some recommendations from Amazon ( full article ):亚马逊的一些建议( 全文):

To get started immediately with .NET 6 on Lambda there are some options:要立即开始使用 .NET 6 on Lambda,有一些选项:

  • Managed base container image - Pull from the ECR Public Gallery or use .NET 6 container image Blueprint in the AWS Toolkit for Visual Studio.托管基础容器映像 - 从 ECR 公共库中提取或使用 AWS Toolkit for Visual Studio 中的 .NET 6 容器映像蓝图。
  • Custom container image - Build a container image with the .NET 6 application packaged inside it.自定义容器镜像 - 构建容器镜像,其中打包了 .NET 6 应用程序。 This PowerShell script will build a .NET 6 base container image.这个 PowerShell 脚本将构建一个 .NET 6 基础容器镜像。
  • Custom runtime - The custom runtime bundles all necessary .NET 6 libraries in the zip file archive that is deployed to Lambda, see this example.自定义运行时 - 自定义运行时将所有必需的 .NET 6 个库捆绑在部署到 Lambda 的 zip 文件存档中,请参阅此示例。 For an ARM64 see this example.对于 ARM64,请参阅此示例。

Managed instances with .NET 6 should be available in the near future.具有 .NET 6 的托管实例应该在不久的将来可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM