简体   繁体   English

ASP.NET AWS 中托管的 Core 6 应用程序 Lambda function URL 处理程序

[英]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.

相关问题 如何在 AWS 上托管 ASP.NET 核心 Blazor WebAssembly 托管应用程序? - How to host an ASP.NET Core Blazor WebAssembly Hosted App on AWS? AWS Fargate 如何处理其中托管的 ASP.NET Core 应用程序的健康状况? - How does AWS Fargate handle the health status of ASP.NET Core app hosted in it? 哪个端口是我在 AWS Fargate 中运行的 ASP.NET Core 6 应用程序 - Which port is my ASP.NET Core 6 app running on in AWS Fargate 从ASP.NET Core访问Azure App Service ConnectionString - Access Azure App Service ConnectionString from ASP.NET Core .NET 5 ASP.NET 核心应用程序未在 Azure 中启动 - .NET 5 ASP.NET Core App not starting in Azure AWS Golang Lambda 处理程序 function 未被调用 - AWS Golang Lambda handler function not getting called .NET Core cookie 身份验证与 AWS Lambda 不持久 - .NET Core cookie authentication with AWS Lambda not persisting 使用 Cognito 登录 AWS Lambda.Net Core - Login in AWS Lambda .Net Core with Cognito .Net Core - AWS Lambda 启用 DI 的项目 - .Net Core - AWS Lambda Project enabling DI ASP.net 核心 docker https on Azure 应用服务容器 - ASP.net core docker https on Azure App Service Containers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM