diff --git a/docs/usage.rst b/docs/usage.rst index 5fb7f3c4d0..ee12e26f24 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -488,6 +488,88 @@ attach to a debug session. } +Debugging .NET Core 2.1 / 2.0 Functions +--------------------------------------- + +.NET Core function debugging is similiar to golang function debugging and requires you to have ``vsdbg`` available on your +machine to later provide it to SAM CLI. VS Code will launch debugger inside Lambda container and talk to it using ``pipeTransport`` configuration. + +When debugging, you must compile your function in debug mode: + +Either locally using .NET SDK + +.. code:: bash + + dotnet publish -c Debug -o + +Or via Docker + +.. code:: bash + + docker run --rm --mount type=bind,src=$PWD,dst=/var/task lambci/lambda:build-dotnetcore dotnet publish -c Debug -o + +**NOTE: both of these commands should be run from the directory with .csproj file** + +You must get ``vsdbg`` built for AWS Lambda runtime container on your host machine and provide its local path +via the ``--debugger-path`` argument. Get compatible debugger version as follows: + +.. code:: bash + + # Create directory to store vsdbg + mkdir + + # Get and install vsdbg on runtime container. Mounted folder will let you have it under on your machine too + docker run --rm --mount type=bind,src=,dst=/vsdbg --entrypoint bash lambci/lambda:dotnetcore2.0 -c "curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l /vsdbg" + +Then invoke ``sam`` similar to the following: + +``sam local start-api -d --debugger-path `` + +NOTE: The ``--debugger-path`` is the path to the directory that contains the ``vsdbg`` binary installed from the above. + +The following is an example launch configuration for Visual Studio Code to attach to a debug session. + +.. code:: json + + { + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Docker Attach", + "type": "coreclr", + "request": "attach", + "processId": "1", + + "pipeTransport": { + "pipeProgram": "sh", + "pipeArgs": [ + "-c", + "docker exec -i $(docker ps -q -f publish=) ${debuggerCommand}" + ], + "debuggerPath": "/tmp/lambci_debug_files/vsdbg", + "pipeCwd": "${workspaceFolder}", + }, + + "windows": { + "pipeTransport": { + "pipeProgram": "powershell", + "pipeArgs": [ + "-c", + "docker exec -i $(docker ps -q -f publish=) ${debuggerCommand}" + ], + "debuggerPath": "/tmp/lambci_debug_files/vsdbg", + "pipeCwd": "${workspaceFolder}", + } + }, + + "sourceFileMap": { + "/var/task": "${workspaceFolder}" + } + } + ] + } + + Passing Additional Runtime Debug Arguments ------------------------------------------ diff --git a/samcli/local/docker/lambda_container.py b/samcli/local/docker/lambda_container.py index 1a9c06a7da..f4a2a715e6 100644 --- a/samcli/local/docker/lambda_container.py +++ b/samcli/local/docker/lambda_container.py @@ -203,6 +203,14 @@ def _get_entry_point(runtime, debug_options=None): "/var/runtime/lib/LambdaJavaRTEntry-1.0.jar", ] + elif runtime in (Runtime.dotnetcore20.value, Runtime.dotnetcore21.value): + entrypoint = ["/var/lang/bin/dotnet"] \ + + debug_args_list \ + + [ + "/var/runtime/MockBootstraps.dll", + "--debugger-spin-wait" + ] + elif runtime == Runtime.go1x.value: entrypoint = ["/var/runtime/aws-lambda-go"] \ + debug_args_list \ @@ -289,8 +297,9 @@ def _get_entry_point(runtime, debug_options=None): @staticmethod def _supported_runtimes(): - return {Runtime.java8.value, Runtime.go1x.value, Runtime.nodejs.value, Runtime.nodejs43.value, - Runtime.nodejs610.value, Runtime.nodejs810.value, Runtime.python27.value, Runtime.python36.value} + return {Runtime.java8.value, Runtime.dotnetcore20.value, Runtime.dotnetcore21.value, Runtime.go1x.value, + Runtime.nodejs.value, Runtime.nodejs43.value, Runtime.nodejs610.value, Runtime.nodejs810.value, + Runtime.python27.value, Runtime.python36.value} class DebuggingNotSupported(Exception): diff --git a/tests/unit/local/docker/test_lambda_container.py b/tests/unit/local/docker/test_lambda_container.py index 58675affef..31df5d7b46 100644 --- a/tests/unit/local/docker/test_lambda_container.py +++ b/tests/unit/local/docker/test_lambda_container.py @@ -10,6 +10,8 @@ from samcli.local.docker.lambda_container import LambdaContainer, Runtime, DebuggingNotSupported RUNTIMES_WITH_ENTRYPOINT = [Runtime.java8.value, + Runtime.dotnetcore20.value, + Runtime.dotnetcore21.value, Runtime.go1x.value, Runtime.nodejs.value, Runtime.nodejs43.value,