Open thomaswr opened 1 day ago
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)
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)
Version 0.16.0
of the test tool has been released that fixes the issue. Thanks for reporting the issue.
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
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
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 LambdaTestToolPossible 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