AWS Gateway子分量支持ASP.NET Core
我创建了一个简单的AWS无服务器“ ASP.NET Core Minimal”应用程序,并且一切都按预期工作,因为应用程序(Lambda)绑定到API网关的根路由。 这是配置:
"Events": {
"ProxyResource": {
"Type": "Api",
"Properties": {
"Path": "/{proxy+}",
"Method": "ANY"
}
},
"RootResource": {
"Type": "Api",
"Properties": {
"Path": "/",
"Method": "ANY"
}
}
}
但是,如果要将根路由更改为某些子程序,例如“/Hello” ,
"Events": {
"ProxyResource": {
"Type": "Api",
"Properties": {
"Path": "/hello/{proxy+}",
"Method": "ANY"
}
},
"RootResource": {
"Type": "Api",
"Properties": {
"Path": "/hello/",
"Method": "ANY"
}
}
}
一切都停止工作,并且应用程序不断返回404错误而不是欢迎消息。
这是应用程序代码:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddAWSLambdaHosting(LambdaEventSource.RestApi);
builder.Services.AddSwaggerGen();
var app = builder.Build();
app.MapControllers();
app.MapGet("/", () => "Welcome to running ASP.NET Core Minimal API on AWS Lambda");
app.Run();
是否有可能以某种方式解释该应用程序现在已绑定到子程序的应用程序?
I have created a simple AWS Serverless "Asp.Net Core minimal" application and everything works as expected because the application(lambda) is bound to the root route of the Api gateway.
Here is the configuration:
"Events": {
"ProxyResource": {
"Type": "Api",
"Properties": {
"Path": "/{proxy+}",
"Method": "ANY"
}
},
"RootResource": {
"Type": "Api",
"Properties": {
"Path": "/",
"Method": "ANY"
}
}
}
But if to change the root route to some subroute, for example "/hello",
"Events": {
"ProxyResource": {
"Type": "Api",
"Properties": {
"Path": "/hello/{proxy+}",
"Method": "ANY"
}
},
"RootResource": {
"Type": "Api",
"Properties": {
"Path": "/hello/",
"Method": "ANY"
}
}
}
everything stops working and the application constantly returns a 404 error instead of a welcome message.
Here is the application code:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddAWSLambdaHosting(LambdaEventSource.RestApi);
builder.Services.AddSwaggerGen();
var app = builder.Build();
app.MapControllers();
app.MapGet("/", () => "Welcome to running ASP.NET Core Minimal API on AWS Lambda");
app.Run();
Is it possible somehow to explain for the application that now it is bound to the subroute?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要更改功能中的URL。它需要像:
如果您有任何路由参数,也可以使用
you need to change the url in function. It needs to be like:
And if you have any route parameters you can also use