-
Notifications
You must be signed in to change notification settings - Fork 489
Lambda Test Tool using wrong directory to find configuration JSON files #1482
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
Comments
Hi @BradKnowles, Good morning. Thanks for reporting the issue. The root path for the file provider used by Thanks, |
I was doing some more testing and everything works correctly if the project is made from the |
@BradKnowles The project created from Thanks, |
This issue has not received a response in 5 days. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled. |
@ashishdhingra I asked @BradKnowles to submit this. The problem is the test tool's process has its current working directory set to where it was executed so if the Lambda function is looking for files relative to its location thinking that is where the current working directory is then it will fail. We need to make sure before we call the function that we change the Lambda test tool process's current working directory to the location of the Lambda function so the behavior will be the same as it is in the real Lambda service. |
Is there any more help I can provide in tracking this down? |
@normj Changing the current process directory by using the
So Selecting Copy to Output Directory as
It searches for JSON file only in lambda test tool directory, perhaps due to above reasoning. |
In the current test tool there is not a way to fix this issue. The good news is we are working on a new version of the test tool. The design of new version is the test tool is always out of process so doesn't interfere with how the project is loaded, working directories or dependency resolution. Currently the focus is on Aspire integration with the new tool which you can read about here. aws/integrations-on-dotnet-aspire-for-aws#17 We don't have any documentation yet on how to use the new tooling outside of Aspire and the experience isn't smooth yet. We will make it better. But if you want to try it out here are some rough instructions.
Make sure new profile is selected and then push F5 for debugging. You can go back to the test tool's web page and add events to start debugging. Your issue about not find the config files because the working directory is set to where the test to is installed at goes away because the working directory is set by the launchsettings.json file as you can see above. We plan on making this setup more automatic in the future but hopefully this is enough for you to start trying the new tooling. I'm going to close this because our focus is on the new tooling and this is not an issue with the new tooling. |
Comments on closed issues are hard for our team to see. |
Describe the bug
When using
Microsoft.Extensions.Configuration.Json
version7.0.0
and specifying a path for a JSON file, like sologging.json
is not found, even when present in the output directory.Instead of searching
..\bin\Debug\net6.0\logging.json
it uses%USERPROFILE%\.dotnet\tools\.store\amazon.lambda.testtool-6.0\0.13.0\amazon.lambda.testtool-6.0\0.13.0\tools\net6.0\any\logging.json
.If specifying
appsettings.json
in theAddJsonFile()
method, theappsettings.json
file from the Mock Lambda Test tool is injected intologConfig
instead of the one supplied with the Lambda project.Expected Behavior
I expect
logging.json
to be parsed from..\bin\Debug\net6.0\logging.json
and become part of thelogConfig
configuration as mentioned above.Current Behavior
logging.json
is serached for in%USERPROFILE%\.dotnet\tools\.store\amazon.lambda.testtool-6.0\0.13.0\amazon.lambda.testtool-6.0\0.13.0\tools\net6.0\any\logging.json
, is not found, andlogConfig
remains empty.Reproduction Steps
AWS Lambda Project (.NET Core - C#)
templateEmpty Function
BlueprintMicrosoft.Extensions.Configuration.Json
version7.0.0
NuGet packageusing Microsoft.Extensions.Configuration;
to the top ofFunction.cs
FunctionHandler
""
for the function input.This will throw an exception saying it can't find
logging.json
, which is correct since we didn't add the file. However, the error message will show the path it tried to search for the file. Instead of searching..\AWSLambda1\AWSLambda1\bin\Debug\net6.0\logging.json
it uses%USERPROFILE%\.dotnet\tools\.store\amazon.lambda.testtool-6.0\0.13.0\amazon.lambda.testtool-6.0\0.13.0\tools\net6.0\any\logging.json
.Possible Solution
I believe the issue might be in this area. Even though
AppBaseCompilationAssemblyResolver(Path.GetDirectoryName(rootAssemblyPath))
uses the correct directory, debugging into .NET source shows thatDependencyContext
of theassemblyResolver
points to the wrong location. This is still a educated guess though, I wasn't able to dig too much further as of yet.aws-lambda-dotnet/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool/Runtime/LambdaAssemblyLoadContext.cs
Lines 124 to 130 in 630d1d3
Additional Information/Context
A workaround does exist. Adding
.SetBasePath(Environment.CurrentDirectory)
to theConfigurationBuilder
will cause the configuration system to use the correct path.AWS .NET SDK and/or Package version used
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
Targeted .NET Platform
.NET 6
Operating System and version
Windows 10
The text was updated successfully, but these errors were encountered: