1
votes

I'm using VS Code to write Lambda functions using the dotnet core 2.0 CLI.

  • VS Code v1.24.1
  • dotnet Core CLI v2.1.200

Problem
I can't get the debugger to work locally with the function I've written in VS Code.

I place a breakpoint on the line var body = request?.Body; (See Function.cs code block below). When I then click the start debugging button in the Debug tab in VS Code, I get the following:

-------------------------------------------------------------------
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

The Lambda Function uses the APIGatewayEvents package to accept a request from the 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

I've configured this to use the Function.cs dll's (The file that was created by vs code was hitting the test project)

"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}"
    }
}

I've seen this post here:
https://cloudncode.blog/2017/01/24/getting-started-with-writing-and-debugging-aws-lambda-function-with-visual-studio-code/

But I don't think this method will work for dotnet core 2.0. I've also done a lot of googling and have found almost no information on how to debug dotnet core 2.0 functions in VS Code.

2

2 Answers

1
votes

OK so I found this, which says it's not possible at the moment:

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

Am moving to NodeJs and the Serverless package to do this for now:

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

Will update this if / when things change for dotnet core

0
votes

processId it should be set to 1, because Docker assigns entry point executable PID of 1. It is in launch.json of VS Code.