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

Using Amazon.Lambda.Core 2.4.0 breaks running locally with Amazon.Lambda.TestTool-8.0 0.15.3 #1869

Closed
1 task
thomaswr opened this issue Nov 13, 2024 · 4 comments
Labels

Comments

@thomaswr
Copy link

thomaswr commented Nov 13, 2024

Describe the bug

I want to update Amazon.Lambda.Core in order to use JSON logging but this currently breaks running the lambda locally via LambdaTestTool.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

I want to update Amazon.Lambda.Core in order to use JSON logging but this currently breaks running the lambda locally via LambdaTestTool invokes lambda and I get JSON formatted as described in the blog post: https://aws.amazon.com/blogs/developer/structured-logging-for-net-lambda/

Current Behavior

System.MissingMethodException: Method not found: 'Void Amazon.Lambda.Core.ILambdaLogger.LogInformation(System.String, System.Object[])'.
   at unzip_ftp_upload.Function.FunctionHandler(CloudWatchEvent`1 input, ILambdaContext context)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at unzip_ftp_upload.Function.FunctionHandler(CloudWatchEvent`1 input, ILambdaContext context)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)

Press any key to exit
Unknown error occurred causing process exit: Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read.
   at System.ConsolePal.ReadKey(Boolean intercept)
   at Amazon.Lambda.TestTool.TestToolStartup.ExecuteWithNoUi(LocalLambdaOptions localLambdaOptions, CommandLineOptions commandOptions, String lambdaAssemblyDirectory, RunConfiguration runConfiguration) in C:\build\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\TestToolStartup.cs:line 175
   at Amazon.Lambda.TestTool.TestToolStartup.Startup(String productName, Action`2 uiStartup, String[] args, RunConfiguration runConfiguration) in C:\build\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\TestToolStartup.cs:line 79

Reproduction Steps

Implement Lambda using Amazon.Lambda.Core 2.4.0, making use of the ILambdaContext.Logger and using the second parameter of e.g. LogInformation.
Example: context.Logger.LogInformation("User name is: {user}", user);
Then run it with the LambdaTestTool

Possible Solution

Update Amazon.Lambda.Core Dependency in LambdaTestTool to 2.4.0

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

Amazon.Lambda.TestTool-8.0 0.15.3

Targeted .NET Platform

.NET 8

Operating System and version

Ubuntu

@thomaswr thomaswr added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 13, 2024
@ashishdhingra ashishdhingra added module/lambda-client-lib module/lambda-test-tool p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Nov 13, 2024
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Nov 13, 2024

Issue reproducible using Lambda Test Tool 8.0 version 0.15.3 when we use structured logging as shown below:
Function.cs

using Amazon.Lambda.Core;

[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace TestNet8Lambda;

public class Function
{
    public string FunctionHandler(string input, ILambdaContext context)
    {
        context.Logger.LogInformation("Input is: {input}", input);
        return input.ToUpper();
    }
}

.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <AWSProjectType>Lambda</AWSProjectType>
    <!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. -->
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <!-- Generate ready to run images during publishing to improve cold start time. -->
    <PublishReadyToRun>true</PublishReadyToRun>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Amazon.Lambda.Core" Version="2.4.0" />
    <PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" />
  </ItemGroup>
</Project>

Amazon.Lambda.Core (2.4.0) had RequiresPreviewFeatures removed as part of the commit. Amazon.Lambda.TestTool.csproj has package reference to Amazon.Lambda.Core (2.2.0). We might need to release new Lambda Test Tool version which references the latest Amazon.Lambda.Core (2.4.0).

@thomaswr Please confirm if it was working with previous version Amazon.Lambda.Core (2.3.0)

@ashishdhingra ashishdhingra self-assigned this Nov 13, 2024
@ashishdhingra ashishdhingra added needs-reproduction This issue needs reproduction. needs-review and removed needs-reproduction This issue needs reproduction. labels Nov 13, 2024
@ashishdhingra ashishdhingra removed their assignment Nov 13, 2024
@ashishdhingra ashishdhingra added p1 This is a high priority issue and removed p2 This is a standard priority issue labels Nov 13, 2024
@thomaswr
Copy link
Author

It works with Amazon.Lambda.Core 2.3.0, if not using structured logging.
Build fails with Amazon.Lambda.Core 2.3.0, if using structured logging with:

error CA2252: Parameterized logging is in preview till a new version of .NET Lambda runtime client that supports parameterized logging has been deployed to the .NET Lambda managed runtime.
Till deployment has been made the feature can be used by deploying as an executable including the latest version of Amazon.Lambda.RuntimeSupport and setting the "EnablePreviewFeatures" in the Lambda project file to "true" Using 'LogInformation' requires opting into preview features.
See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

@normj
Copy link
Member

normj commented Nov 15, 2024

Version 0.16.0 of the test tool has been released that fixes the issue. Thanks for reporting the issue.

Copy link
Contributor

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
Projects
None yet
Development

No branches or pull requests

3 participants