【问题标题】:Debug dotnet core 2.0 AWS Lambda Functions in VS Code (C#)在 VS Code (C#) 中调试 dotnet core 2.0 AWS Lambda 函数
【发布时间】:2018-07-04 20:18:14
【问题描述】:

我正在使用 VS Code 使用 dotnet core 2.0 CLI 编写 Lambda 函数。

  • VS 代码 v1.24.1
  • dotnet Core CLI v2.1.200

问题
我无法让调试器使用我在 VS Code 中编写的函数在本地工作。

我在var body = request?.Body; 行上放置了一个断点(参见下面的 Function.cs 代码块)。然后,当我单击 VS Code 中 Debug 选项卡中的 start debugging 按钮时,我得到以下信息:

-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.7\System.Private.CoreLib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded 'C:\Users\chris\Documents\Github\tcdevs\resource-it\client-management-lambda\ClientManagement.TestAsyncFunction\test\ClientManagement.TestAsyncFunction.Tests\bin\Debug\netcoreapp2.0\ClientManagement.TestAsyncFunction.Tests.dll'. Symbols loaded.
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.7\System.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The program '[49584] ClientManagement.TestAsyncFunction.Tests.dll' has exited with code 0 (0x0).

函数.cs

Lambda 函数使用 APIGatewayEvents 包接受来自 API Gateway 的请求

public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
{
    var body = request?.Body;

    // do something asynchronously

    return new APIGatewayProxyResponse()
    {
        Body = JsonConvert.SerializeObject(body),
        StatusCode = 200,
        Headers = new Dictionary<string, string>{ {"Content-Type", "application/json"} }
    };
}

launch.json

我已将其配置为使用 Function.cs dll(由 vs 代码创建的文件正在命中测试项目)

"version": "0.2.0",
"configurations": [
    {
        "name": ".NET Core Launch (lambda)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "build",
        "program": "${workspaceFolder}/src/ClientManagement.TestAsyncFunction/bin/Debug/netcoreapp2.0/ClientManagement.TestAsyncFunction.dll",
        "args": [],
        "cwd": "${workspaceFolder}/src/ClientManagement.TestAsyncFunction",
        "console": "internalConsole",
        "stopAtEntry": false,
        "internalConsoleOptions": "openOnSessionStart"
    },
    {
        "name": ".NET Core Attach",
        "type": "coreclr",
        "request": "attach",
        "processId": "${command:pickProcess}"
    }
}

我在这里看到了这篇文章:
https://cloudncode.blog/2017/01/24/getting-started-with-writing-and-debugging-aws-lambda-function-with-visual-studio-code/

但我认为这种方法不适用于 dotnet core 2.0。我也做了很多谷歌搜索,几乎没有找到关于如何在 VS Code 中调试 dotnet core 2.0 函数的信息。

【问题讨论】:

    标签: c# amazon-web-services visual-studio-code .net-core aws-lambda


    【解决方案1】:

    好的,所以我找到了这个,它说目前不可能:

    https://github.com/aws/aws-lambda-dotnet/issues/246

    我现在正在转向 NodeJs 和无服务器包来执行此操作:

    https://www.npmjs.com/package/serverless

    如果/当 dotnet 核心发生变化时将更新此内容

    【讨论】:

      【解决方案2】:

      processId 应该设置为 1,因为 Docker 分配的入口点可执行 PID 为 1。它在 VS Code 的 launch.json 中。

      【讨论】:

        猜你喜欢
        • 2018-12-02
        • 2019-10-10
        • 2020-12-30
        • 1970-01-01
        • 2018-02-05
        • 2020-08-25
        • 2017-09-26
        • 2021-03-19
        • 1970-01-01
        相关资源
        最近更新 更多