-
Notifications
You must be signed in to change notification settings - Fork 480
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
Amazon.Lambda.CloudWatchEvents definition doesn't work with Newtonsoft.Json when compiling on .NET Core 3.1 #634
Comments
I'm not sure why you would see any change in behavior when targeting .NET Core 3.1. There wasn't any special logic for |
Maybe I jumped the gun. Here's what I saw in the CloudWatch logs when I emitted the received event. Notice how {
"Version": "0",
"Account": "xyz",
"Region": "us-west-2",
"Detail": {
"Message": "hello world!"
},
"DetailType": null,
"Source": "LambdaSharp.Sample",
"Time": "2020-04-18T01:15:39Z",
"Id": "ab26e799-0b3b-637c-2f96-6a428401fdf3",
"Resources": [
"lambdasharp:stack:SteveBvNext-Sample-Event",
"lambdasharp:module:Sample.Event",
"lambdasharp:tier:SteveBvNext"
]
} This is the actual event that was sent: {
"version": "0",
"id": "ab26e799-0b3b-637c-2f96-6a428401fdf3",
"detail-type": "MyFirstEvent",
"source": "LambdaSharp.Sample",
"account": "xyz",
"time": "2020-04-18T01:15:39Z",
"region": "us-west-2",
"resources": [
"lambdasharp:stack:SteveBvNext-Sample-Event",
"lambdasharp:module:Sample.Event",
"lambdasharp:tier:SteveBvNext"
],
"detail": {
"Message": "hello world!"
}
} This is the code I used, following the pre-3.1 pattern: [assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
namespace Sample.Event.ReceiverFunction {
public class EventDetails {
//--- Properties ---
public string? Message { get; set; }
}
public class FunctionResponse { }
public class Function : ALambdaFunction<CloudWatchEvent<EventDetails>, FunctionResponse> {
//--- Methods ---
public override async Task InitializeAsync(LambdaConfig config) { }
public override async Task<FunctionResponse> ProcessMessageAsync(CloudWatchEvent<EventDetails> request) {
LogInfo(SerializeJson(request));
return new FunctionResponse();
}
}
} For context, It's certainly possible that the issue was present before 3.1. I didn't test it until now. |
I think I figured it out! The problem stems from this line line:
The code requires that the serialized type MUST belong to the Buggy VersionIn the first version, I use namespace CloudWatchEventListener {
public class EventDetails {
//--- Properties ---
public string Message { get; set; }
}
public class Function {
//--- Methods ---
public string FunctionHandler(CloudWatchEvent<EventDetails> request, ILambdaContext context) {
Console.WriteLine($"DetailType = {request.DetailType}"); // <-- DetailType is empty
return "Okay";
}
}
} Fixed VersionIn this version, I created a derived type in the namespace Amazon.Lambda.CloudWatchEvents {
public class MyCloudWatchEvent : CloudWatchEvent<CloudWatchEventListener.EventDetails> { }
}
namespace CloudWatchEventListener {
public class EventDetails {
//--- Properties ---
public string Message { get; set; }
}
public class Function {
//--- Methods ---
public string FunctionHandler(MyCloudWatchEvent request, ILambdaContext context) {
Console.WriteLine($"DetailType = {request.DetailType}"); // <-- DetailType is shown
return "Okay";
}
}
} I created a repository with both function version. Hopefully that helps in reproducing and fixing this issue. Assuming it's still relevant since it only applies to |
Any hope of getting this fixed eventually? |
Probable fix is to remove condition
Needs review from development team. |
We have noticed this issue has not received attention in 1 year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue. |
Do not close. |
This is causing me an issue right now as well. The offending line is in fact the second part of the condition mentioned in #634 (comment) since the base type of, for instance,
which is, obviously, fairly weird. I think what the author was intending to do was check that the current type is a reification of an open generic type |
Reproducible using customer provided sample code. The condition at
Instead the condition should be logical |
Fix released in Amazon.Lambda.Serialization.Json 2.2.2 |
Comments on closed issues are hard for our team to see. |
For .NET Core 3.1 compilation target,
Amazon.Lambda.CloudWatchEvents
automatically assumes that the function usesSystem.Text.Json
. However, if it usesNewtonsoft.Json
like before, because only the target framework was changed, then theDetailType
property is not properly deserialized.The problematic line is here: https://github.com/aws/aws-lambda-dotnet/blob/master/Libraries/src/Amazon.Lambda.CloudWatchEvents/CloudWatchEvent.cs#L43
The text was updated successfully, but these errors were encountered: