Search code examples
c#amazon-web-servicesaws-lambdanative-aot

Debug C# NativeAOT Lambda Function


I created a .NET 7.0 NativeAOT Lambda function from the AWS Templates. I haven't changed it. I installed the Mock Lambda Test Tool. I believe I have to use the Executable Assembly page to test my function? I can't figure out how to test it though. Do I need to set up docker and sam to test it locally? Or do I just build my C# and run the tool? It's just supposed to take a string and convert it to upper case. I haven't been able to find a tutorial on how to do this...

I tried running the Mock Lambda Test Tool 7.0. I was expecting to send my function a string and it return an uppercase string.

I'm running VS Code on Linux. Here's my launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            // Use IntelliSense to find out which attributes exist for C# debugging
            // Use hover for the description of the existing attributes
            // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // If you have changed target frameworks, make sure to update the program path.
            //"program": "${workspaceFolder}/DocGenerator/bin/Debug/net7.0/linux-x64/bootstrap.dll",
            "program": "${env:HOME}/.dotnet/tools/dotnet-lambda-test-tool-7.0",
            "args": ["--port 5050"],
            "cwd": "${workspaceFolder}/DocGenerator",
            // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
            "console": "internalConsole",
            "stopAtEntry": false
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach"
        }
    ]
}

This is my aws-lambda-tools-default.json:

{
  "Information": [
    "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
    "To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",
    "dotnet lambda help",
    "All the command line options for the Lambda command can be specified in this file."
  ],
  "profile": "default",
  "region": "us-east-1",
  "configuration": "Release",
  "function-runtime": "provided.al2",
  "function-memory-size": 256,
  "function-timeout": 30,
  "function-handler": "bootstrap",
  "msbuild-parameters": "--self-contained true"
}

Solution

  • Please check the "launchSettings.json" file under properties folder change the "executablePath" Path and "workingDirectory" and try to run and debug the code,

    it should work. code here "executablePath": "%USERPROFILE%\.dotnet\tools\dotnet-lambda-test-tool-7.0.exe", "commandLineArgs": "--port 5050", "workingDirectory": ".\bin\$(Configuration)\net7.0",