Skip to content

Commit

Permalink
Feature: .NET Core 2.0/2.1 debugging support (aws#825)
Browse files Browse the repository at this point in the history
* Enable .NET Core debugging

* Minor improvements

* Fix code formatting
  • Loading branch information
ndobryanskyy authored and sriram-mv committed Dec 5, 2018
1 parent dc6819b commit 100920e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
82 changes: 82 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <output path>
Or via Docker

.. code:: bash
docker run --rm --mount type=bind,src=$PWD,dst=/var/task lambci/lambda:build-dotnetcore<target-runtime> dotnet publish -c Debug -o <output path relative to $PWD>
**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 <vsdbg folder path>
# Get and install vsdbg on runtime container. Mounted folder will let you have it under <vsdbg folder path> on your machine too
docker run --rm --mount type=bind,src=<vsdbg folder path>,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 <debug port> --debugger-path <vsdbg folder 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=<debug port>) ${debuggerCommand}"
],
"debuggerPath": "/tmp/lambci_debug_files/vsdbg",
"pipeCwd": "${workspaceFolder}",
},
"windows": {
"pipeTransport": {
"pipeProgram": "powershell",
"pipeArgs": [
"-c",
"docker exec -i $(docker ps -q -f publish=<debug port>) ${debuggerCommand}"
],
"debuggerPath": "/tmp/lambci_debug_files/vsdbg",
"pipeCwd": "${workspaceFolder}",
}
},
"sourceFileMap": {
"/var/task": "${workspaceFolder}"
}
}
]
}
Passing Additional Runtime Debug Arguments
------------------------------------------

Expand Down
13 changes: 11 additions & 2 deletions samcli/local/docker/lambda_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/local/docker/test_lambda_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 100920e

Please sign in to comment.