c# - 无法使用 Mock Lambda 测试工具启动 lambda

标签 c# aws-lambda

我已经使用 AWS lambda 几个月了。我正在使用 lambda 并且在一天结束时一切正常。第二天我回来继续工作,我什至无法让 Visual Studio 使用 Mock Lambda 测试工具启动应用程序。

我最终创建了一个空的 lambda,它只返回输入(AWS 为您提供的标准项目代码作为模板),它甚至不会运行。我点击播放按钮启动模拟 Lambda 测试工具,它看起来会运行几秒钟,然后关闭。命令窗口甚至不会弹出。

这是模板项目中的代码。

public string FunctionHandler(string input, ILambdaContext context)
{
    return input?.ToUpper();
}

这就是我在 VS 的输出窗口中得到的全部信息:

The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core. The program '[16700] dotnet-lambda-test-tool-2.1.exe: Program Trace' has exited with code 0 (0x0). The program '[16700] dotnet-lambda-test-tool-2.1.exe' has exited with code -2147450726 (0x8000809a).



我试过重新安装 AWS 工具包,也试过重新安装 Visual Studio。这是 VS 2017 和 VS 2019 的问题。我刚刚安装了 2019 以查看是否可以解决该问题。任何帮助,将不胜感激。

最佳答案

我遇到了同样的问题。安装 AWS Toolkit 后,我​​发现未安装 lambda 测试工具,因此我遇到了与 OP 相同的错误。唯一的区别是我的目标是 .Net Core 3.1,因此我需要 amazon.lambda.testool-3.1。然而,这个答案应该适用于这两种情况。
不幸的是,我没有像 OP 那样幸运,因为我有一个很好的同事可以给我我需要的文件。所以,如果这也是你的情况,请继续阅读。
在官方项目站点,可以找到here ,有安装工具的说明。它还说安装最新版本的 AWS Toolkit 应该足以安装这些工具(这不是我的情况,可能是您的情况)。
它说为了安装这些工具,您应该运行以下命令:

dotnet tool install -g Amazon.Lambda.TestTool-3.1
或者
dotnet tool install -g Amazon.Lambda.TestTool-2.1
取决于您需要哪种工具。
但是,运行这些命令失败并显示以下消息:
无法恢复工具包。
工具“amazon.lambda.testtool-2.1”安装失败。此故障可能是由以下原因引起的:
* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET Core tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.

For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool
由于该项目仍处于预览阶段,我只需要找到最新的稳定版本即可在命令中指定它。对于 .net 核心 3.1 here是 nuget 站点,我发现 0.10 版是最新的,所以命令应该如下所示:
dotnet tool install -g --version 0.10 Amazon.Lambda.TestTool-3.1

关于c# - 无法使用 Mock Lambda 测试工具启动 lambda,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58599978/

相关文章:

c# - 用于 OnItemDataBound

c# - 如何计算三个数之间的最大公约数

c# - 如何在 WPF 中获取与桌面相关的鼠标位置?

git - 如何在 Terraform 中使用 git 存储库作为 AWS Lambda 源?

amazon-web-services - 如何运行 AWS Lambda 函数来让我知道 CloudFormation 已完成整个堆栈创建

ios - 从 Cognito 向客户端发布身份验证自定义响应

json - 如何在集成请求 (AWS APIGateway) 中取消转义请求路径

C# 等效于 "My.Computer.Network.Ping"

c# - JsonConverter 属性 : deserialize using custom constructor and Autofac

node.js - 我如何在 AWS Lambda 中返回状态代码和响应