![](/img/trans.png)
[英].NET Core 3.1 - Dependency resolution failed for component - AWS Mock Lambda Test Tools
[英]Failed to find method - AWS .NET Core 3.1 Mock Lambda Test Tool
我正在嘗試使用/設置 AWS .NET Core 3.1 Mock Lambda 測試工具。
目前我將通過該工具啟動應用程序,但是,一旦我嘗試發送請求,我就會收到錯誤“無法找到方法 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
路徑,那么我可以讓它為類型拋出錯誤。 但我不明白為什么它找不到 function Init? 應用程序構建並且LambdaProgram
正在根據需要實現 AWS 接口。
任何幫助都會很棒,我真的希望能夠在部署之前在本地進行測試/調試(這是生產中的現有應用程序 - 這只是 lamabda 遷移的一個案例)
在完全困惑了幾個小時之后,我找到了解決方案。 這可能在文檔中,但我沒有看到它,但function-handler
不是 LambdaProgram class (或任何你稱之為你的)內的 function 。
相反,您應該使用我猜是繼承的FunctionHandlerAsync
。
我通過克隆官方存儲庫並查看他們的示例找到了這一點,其中有一條評論詳細說明了這一點!
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>();
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.