Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing documentation on running AOT lambdas in test tool #1539

Closed
SamuelCox opened this issue Jun 27, 2023 · 6 comments
Closed

Missing documentation on running AOT lambdas in test tool #1539

SamuelCox opened this issue Jun 27, 2023 · 6 comments
Assignees
Labels
bug This issue is a bug. documentation This is a problem with documentation. module/lambda-test-tool p2 This is a standard priority issue queued

Comments

@SamuelCox
Copy link

SamuelCox commented Jun 27, 2023

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 SamuelCox added documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged. labels Jun 27, 2023
@ashishdhingra
Copy link
Contributor

@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 ashishdhingra added response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. module/lambda-test-tool and removed needs-triage This issue or PR still needs to be triaged. labels Jun 27, 2023
@SamuelCox
Copy link
Author

image
Still doesn't work

@ashishdhingra
Copy link
Contributor

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 ashishdhingra added bug This issue is a bug. needs-review p2 This is a standard priority issue and removed response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. labels Jun 28, 2023
@ashishdhingra
Copy link
Contributor

Lambda Test Tool documentation (accessible at after launching the tool) is quite elaborate to explain steps for debugging. Hence, closing this issue.


Test Executable Assembly Functions

.NET Lambda functions can be written as an executable assembly. This is done for Lambda functions using custom runtime or using .NET top level statements. These functions include the Lambda runtime client implemented in the Amazon.Lambda.RuntimeSupport NuGet package. In an executable assembly function the Lambda runtime client is initialized and connects to a local REST endpoint for Lambda events to process.

The Executable Assembly page in this tool hosts a local Lambda runtime API for the Lambda runtime client to connect to. On this page you can queue events for the Lambda function to process.

Connect Executable Assembly Functions

To test Lambda function built as an executable assembly the environment variable AWS_LAMBDA_RUNTIME_API must be set to localhost:5050. This will tell Amazon.Lambda.RuntimeSupport to connect to this instance of the test tool for Lambda events to process. To configure AWS credentials and region for the function the environment variables AWS_PROFILE and AWS_REGION can be set.

Here is an example of a .NET executable assembly Lambda function's launchSettings.json file used in Visual Studio for debugging that connects to the test tool and sets the profile and region.

{
  "profiles": {
    "Lambda Runtime API": {
      "commandName": "Project",
      "environmentVariables": {
        "AWS_LAMBDA_RUNTIME_API": "localhost:5050",
        "AWS_PROFILE": "test-profile",
        "AWS_REGION": "us-west-2"
      }
    }
  }
}
    

Programmatically Queue Events

To queue an event to be processed without using the UI send a POST request to http://localhost:5050/runtime/test-event with the JSON Lambda event document as the POST request's body.

@ashishdhingra
Copy link
Contributor

Lambda Test tool Readme at Testing Executable Assemblies has been updated to add steps for debugging executable assemblies.

Copy link
Contributor

github-actions bot commented Nov 6, 2024

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. documentation This is a problem with documentation. module/lambda-test-tool p2 This is a standard priority issue queued
Projects
None yet
Development

No branches or pull requests

2 participants