[英]ASP.NET Core 6 app hosted in AWS Lambda function URL Handler
I have an ASP.NET 6 Web Application (Razor Pages) that was created using the AWS provided template serverless.AspNetCoreWebApp
(from Amazon.Lambda.Templates ), which does not use the new top-level statements approach and scaffolds the following files:我有一个 ASP.NET 6 Web 应用程序 (Razor Pages),它是使用 AWS 提供的模板
serverless.AspNetCoreWebApp
(来自Amazon.Lambda.Templates )创建的,它不使用新的顶级语句方法并构建以下文件:
Startup.cs
LambdaEntryPoint.cs
LocalEntryPoint.cs
I've been successful in deploying this application to Lambda behind API Gateway using the Serverless Framework and using the app.我已经使用无服务器框架和应用程序成功地将此应用程序部署到 API 网关后面的 Lambda。 However, I want to switch to circumvent the use of API Gateway and use Lambda URL instead.
但是,我想改用 API 网关,改用 Lambda URL。 But, I'm unsure what needs to be updated, specifically what do I set the Handler property of my Lambda Function to be when switching to this new approach.
但是,我不确定需要更新什么,特别是在切换到这种新方法时,我将 Lambda Function 的 Handler 属性设置为什么。
I added the package Amazon.Lambda.AspNetCoreServer.Hosting
and in my Startup.cs
added:我添加了 package
Amazon.Lambda.AspNetCoreServer.Hosting
并在我的Startup.cs
中添加了:
services.AddAWSLambdaHosting(LambdaEventSource.HttpApi);
However, I get an Internal Server Error
when hitting the newly provisioned Lambda URL after a successful deployment.但是,在成功部署后点击新配置的 Lambda URL 时出现
Internal Server Error
。 I suspect this is purely a configuration issue.我怀疑这纯粹是配置问题。
All the examples I see online leveraging this new Lambda URL feature is for Minimal API projects that utilize the new top level statements approach for the .NET project;我在网上看到的所有利用这个新的 Lambda URL 功能的示例都是针对 .NET 项目使用新的顶级语句方法的最小 API 项目; where the Lambda Function Handler property is just set to the name of the project's assembly.
其中 Lambda Function Handler 属性刚刚设置为项目程序集的名称。 Leaving the Function Handler set to what it was fronted by API Gateway does not do the trick:
将 Function 处理程序设置为它前面的 API 网关并不能解决问题:
MyApp.Web::MyApp.Web.LambdaEntryPoint::FunctionHandlerAsync
Looking at the provided LambdaEntryPoint
class, which includes guidance about switching the base class based on your architecture (Application Load Balancer, API Gateway Rest/HTTP etc.) there doesn't seem to be something obvious to switch this to for using the Lambda URL approach.查看提供的
LambdaEntryPoint
class,其中包括有关根据您的架构(应用程序负载均衡器、API 网关 Rest/HTTP 等)切换基础 class 的指导。似乎没有明显的东西可以切换到使用 Lambda URL方法。
I tried pointing the Function Handler to the following but that did not do the trick either.我尝试将 Function 处理程序指向以下内容,但这也没有解决问题。
MyApp.Web::MyApp.Web.LocalEntryPoint::Main
Apparently, even in this case where the projects is not using the top-level statements feature, you still utilize just the assembly name as the Lambda Function's handler.显然,即使在项目未使用顶级语句功能的情况下,您仍然仅使用程序集名称作为 Lambda 函数的处理程序。
So in this example case, the Lambda Function Handler property in serverless.yml
should be set to:所以在这个例子中,serverless.yml 中的
serverless.yml
Function Handler 属性应该设置为:
handler: MyApp.Web
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.