aws-lambda-dotnet icon indicating copy to clipboard operation
aws-lambda-dotnet copied to clipboard

Missing documentation on running AOT lambdas in test tool

Open SamuelCox opened this issue 1 year ago • 3 comments

Describe the issue

As far as I can tell, there is no proper documentation on how to use the lambda test tool for .net 7 AOT

{
  "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": "eu-west-1",
  "configuration": "Release",
  "function-runtime": "provided.al2",
  "function-memory-size": 256,
  "function-timeout": 30,
  "function-handler": "bootstrap",
  "msbuild-parameters": "--self-contained true"
}
{
  "profiles": {
    "Mock Lambda Test Tool": {
      "commandName": "Executable",
      "commandLineArgs": "--no-ui --payload payload.json",
      "workingDirectory": ".\\bin\\$(Configuration)\\net7.0",
      "executablePath": "C:\\Users\\%USERNAME%\\.dotnet\\tools\\dotnet-lambda-test-tool-7.0.exe",
      "args": [ "--port 5050" ]

    }
  }
}

throws this error: image

If I listen to the error message (which every amazon sample on line uses "bootstrap" as the handler for aot) then I get this image

Would massively appreciate proper documentation on this and/or a description of what I'm doing wrong

Links

https://github.com/aws/aws-lambda-dotnet/blob/master/Tools/LambdaTestTool/README.md

SamuelCox avatar Jun 27 '23 16:06 SamuelCox

@SamuelCox Thanks for reporting the issue. Please refer to https://github.com/aws/aws-lambda-dotnet/blob/master/Tools/LambdaTestTool/README.md#testing-executable-assemblies for testing Native AOT Lambda functions. These are compiled as executable assemblies. More information can be found in the test tool documentation available at http://localhost:5050/documentation (this is the endpoint after Test tool is launched).

Please let me know if it helps.

Thanks, Ashish

ashishdhingra avatar Jun 27 '23 16:06 ashishdhingra

image Still doesn't work

SamuelCox avatar Jun 28 '23 09:06 SamuelCox

https://github.com/aws/aws-lambda-dotnet/blob/master/Tools/LambdaTestTool/README.md#testing-executable-assemblies

@SamuelCox Here are the updated steps working for me:

  • Install Lambda Test Tool version 7.0 using command dotnet tool install -g Amazon.Lambda.TestTool-7.0.
  • Navigate to project's root directory containing .csproj file.
  • Run dotnet lambda-test-tool-7.0 to launch Lambda Test Tool.
  • As mentioned in Lambda Test Tool 7.0 documentation at http://localhost:5050/documentation, in project's launchSettings.json, specify the environment variables either via Visual Studio Debug UI or modifying the launchSettings.json manually:
{
  "profiles": {
    "LambdaNativeAOT": {
      "commandName": "Project",
      "environmentVariables": {
        "AWS_LAMBDA_RUNTIME_API": "localhost:5050",
        "AWS_PROFILE": "default",
        "AWS_REGION": "us-east-2"
      }
    }
  }
}
  • Setup breakpoint in Lambda Function handler.
  • Debug project using Visual Studio.
  • In Lambda Test Tool's Executable Assembly page, queue the event (for project created using Native AOT Visual Studio AWS template, the handler converts input string to upper case and returns it. Hence we may pass double quoted string, e.g. "Hello World" from test tool)

Breakpoint in Visual Studio should be hit now.

I agree the Lambda Test Tool documentation needs to be elaborated or made more clear.

Thanks, Ashish

ashishdhingra avatar Jun 28 '23 18:06 ashishdhingra