找不到方法 - AWS .NET Core 3.1 Mock Lambda 测试工具
Failed to find method - AWS .NET Core 3.1 Mock Lambda Test Tool
我正在尝试 use/setup AWS .NET Core 3.1 模拟 Lambda 测试工具。
目前我将通过该工具启动应用程序,但是,一旦我尝试发送请求,我就会收到错误 "Failed to find method Init"。
在 aws-lambda-tools-defaults.json
中,我将 function-handler
设置为以下内容:
"function-handler": "Some.Example.Assembly::Some.Example.Namespace.LambdaProgram::Init"
LambdaProgram.cs 文件如下所示:
using Amazon.Lambda.AspNetCoreServer;
using Microsoft.AspNetCore.Hosting;
namespace Some.Example.Namespace
{
public class LambdaProgram : APIGatewayHttpApiV2ProxyFunction
{
protected override void Init(IWebHostBuilder builder)
{
builder.UseStartup<Startup>();
}
}
}
除非我误读了文档,否则格式对我来说似乎是正确的?
在 bin/
目录中,dll 和 exe 具有匹配的名称,即 "Some.Example.Assembly.exe" & "Some.Example.Assembly.dll".
如果我更改 function-handler
路径,那么我可以让它抛出类型错误。但我不明白为什么找不到函数Init?应用程序构建并且 LambdaProgram
正在根据需要实施 AWS 接口。
任何帮助都会很棒,我真的希望能够在部署之前在本地 test/debug(这是生产中的现有应用程序 - 这只是 lamabda 迁移的一个例子)
在完全困惑了几个小时之后,我找到了解决办法。这可能在文档中,但我没有看到它,但 function-handler
不是 LambdaProgram class(或任何你调用的)中的函数。
相反,您应该使用 FunctionHandlerAsync
,我猜它是被继承的。
我通过克隆 official repository 并查看他们的样本发现了这一点,其中有一条评论详细说明了这一点!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using System.IO;
namespace BlueprintBaseName._1
{
/// <summary>
/// This class extends from APIGatewayProxyFunction which contains the method FunctionHandlerAsync which is the
/// actual Lambda function entry point. The Lambda handler field should be set to
///
/// BlueprintBaseName.1::BlueprintBaseName.1.LambdaEntryPoint::FunctionHandlerAsync
/// </summary>
public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
protected override void Init(IWebHostBuilder builder)
{
builder
.UseStartup<Startup>();
}
}
}
我正在尝试 use/setup AWS .NET Core 3.1 模拟 Lambda 测试工具。
目前我将通过该工具启动应用程序,但是,一旦我尝试发送请求,我就会收到错误 "Failed to find method Init"。
在 aws-lambda-tools-defaults.json
中,我将 function-handler
设置为以下内容:
"function-handler": "Some.Example.Assembly::Some.Example.Namespace.LambdaProgram::Init"
LambdaProgram.cs 文件如下所示:
using Amazon.Lambda.AspNetCoreServer;
using Microsoft.AspNetCore.Hosting;
namespace Some.Example.Namespace
{
public class LambdaProgram : APIGatewayHttpApiV2ProxyFunction
{
protected override void Init(IWebHostBuilder builder)
{
builder.UseStartup<Startup>();
}
}
}
除非我误读了文档,否则格式对我来说似乎是正确的?
在 bin/
目录中,dll 和 exe 具有匹配的名称,即 "Some.Example.Assembly.exe" & "Some.Example.Assembly.dll".
如果我更改 function-handler
路径,那么我可以让它抛出类型错误。但我不明白为什么找不到函数Init?应用程序构建并且 LambdaProgram
正在根据需要实施 AWS 接口。
任何帮助都会很棒,我真的希望能够在部署之前在本地 test/debug(这是生产中的现有应用程序 - 这只是 lamabda 迁移的一个例子)
在完全困惑了几个小时之后,我找到了解决办法。这可能在文档中,但我没有看到它,但 function-handler
不是 LambdaProgram class(或任何你调用的)中的函数。
相反,您应该使用 FunctionHandlerAsync
,我猜它是被继承的。
我通过克隆 official repository 并查看他们的样本发现了这一点,其中有一条评论详细说明了这一点!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using System.IO;
namespace BlueprintBaseName._1
{
/// <summary>
/// This class extends from APIGatewayProxyFunction which contains the method FunctionHandlerAsync which is the
/// actual Lambda function entry point. The Lambda handler field should be set to
///
/// BlueprintBaseName.1::BlueprintBaseName.1.LambdaEntryPoint::FunctionHandlerAsync
/// </summary>
public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
protected override void Init(IWebHostBuilder builder)
{
builder
.UseStartup<Startup>();
}
}
}