使用VS Code(C#)调试dotnet core 2.0 AWS Lambda函数

时间:2018-07-04 20:18:15

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

我正在使用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).

Function.cs

Lambda函数使用API​​GatewayEvents包来接受来自API网关的请求

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功能的信息。

2 个答案:

答案 0 :(得分:1)

好,所以我发现了这一点,这表明目前尚不可能:

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

现在转移到NodeJs和Serverless软件包以进行此操作:

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

如果/当点网核心发生变化时,将对此进行更新

答案 1 :(得分:0)

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