amazon-web-services - AWS Lambda 控制器路由不匹配,{proxy+} - 404 Not Found
问题描述
我有一个带有 GET 端点的 .NET core 3.1 项目。本地路由工作正常 - “/api” GET 请求返回 JSON 字符串。
在发布到我的 AWS Lambda 函数并通过 Postman 调用 lambda 后,我收到了对“/api”GET 请求的 404 Not Found 响应。完整 URL:“https://(lambda 域)/default/MyLambda2/api”
在我的项目的 Startup.cs ConfigureServices 和 Configure 方法中,我添加了“LambdaLogger.Log”语句。我的日志行显示在 CloudWatch 中(所以我肯定会到达应用程序)。就在这之后,路线失败了。
在 ConfigureServices 方法中,我有
services.AddControllers();
在配置方法中,我有
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
并在控制器文件中
namespace LambdaTest.Controllers
{
[Route("api")]
public class ValuesController : ControllerBase
{
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
}
我为 lambda 定义了一个 API Gateway 触发器,其中
API endpoint: "https://(lambda domain)/default/MyLambda2/{proxy+}"
API type: REST
Authorization: NONE
Method: ANY
在资源选项卡中,我有...
/MyLambda2
ANY
/{proxy+}
ANY
OPTIONS
...并且我已将所有资源部署到“默认”阶段(通过 Actions > Deploy API)。
这是默认自动生成的 serverless.template 文件...
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Description": "An AWS Serverless Application that uses the ASP.NET Core framework running in Amazon Lambda.",
"Parameters": {},
"Conditions": {},
"Resources": {
"AspNetCoreFunction": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "LambdaTest::LambdaTest.LambdaEntryPoint::FunctionHandlerAsync",
"Runtime": "dotnetcore3.1",
"CodeUri": "",
"MemorySize": 256,
"Timeout": 30,
"Role": null,
"Policies": [
"AWSLambda_FullAccess"
],
"Events": {
"ProxyResource": {
"Type": "Api",
"Properties": {
"Path": "/{proxy+}",
"Method": "ANY"
}
},
"RootResource": {
"Type": "Api",
"Properties": {
"Path": "/",
"Method": "ANY"
}
}
}
}
}
},
"Outputs": {
"ApiURL": {
"Description": "API endpoint URL for Prod environment",
"Value": {
"Fn::Sub": "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
}
}
}
}
什么可能导致路由没有在 lambda 中被拾取?
谢谢
解决方案
发现问题。我需要我在控制器上的路线是
[Route("MyLambda2/api")]
推荐阅读
- reactjs - 条件语句在反应中不起作用
- php - 这是我的 wordpress 安装中的 php 漏洞吗?
我一直在监视我的 wordpress 安装,并且不时在 /wp-content/mu-plugins/wp-nc-easywp/plugin/Http/Checker/ 等位置创建文件
文件名始终以 .1599.... 开头,后跟随机数 ex。.1599674957 或 .1599
- rust - Rust:改变一个 Option 字段,其包装的值没有实现 Copy trait
- python - 布尔值选择错误
- sqlalchemy - 我可以在编写查询时指定关系的连接条件,而不是在我的模型类中这样做吗?
- azure-machine-learning-service - 无法从 azureml-sdk(版本 1.12.0)中的 Datastore 创建 pyspark DataFrame
- rdbms - 使用多个数据库作为后端分区配置 Apache Ignite 集群
- reactjs - 来自 react-transition-group 的 CSSTransition 不应用类
- java - Redis 的 Redisson 的 API 方法 .unlock() 没有释放锁,尝试从同一个实例
- blazor - 允许@onclick for div 吗?