简体   繁体   中英

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:

  • 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. However, I want to switch to circumvent the use of API Gateway and use Lambda URL instead. 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.

I added the package Amazon.Lambda.AspNetCoreServer.Hosting and in my Startup.cs added:

services.AddAWSLambdaHosting(LambdaEventSource.HttpApi);

However, I get an Internal Server Error when hitting the newly provisioned Lambda URL after a successful deployment. 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; where the Lambda Function Handler property is just set to the name of the project's assembly. Leaving the Function Handler set to what it was fronted by API Gateway does not do the trick:

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.

I tried pointing the Function Handler to the following but that did not do the trick either.

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.

So in this example case, the Lambda Function Handler property in serverless.yml should be set to:

handler: MyApp.Web

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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