I have the following code in a .Net 6 Minimal API that is running in an AWS Lambda.
in Program.cs:
app.MapPost("/{id:Guid}/test", TestHandler.Test);
In a separate file:
public static async Task<IResult> Test(TestEvent testEvent, HttpContext context, IConfiguration configuration){
...
}
I get either a 415 using test/json
or a 400 using application/json
. If I remove the POCO:
public static async Task<IResult> Test(HttpContext context, IConfiguration configuration)
I can desearilize the Request.Body without any issues.
string body = await new StreamReader(context.Request.Body).ReadToEndAsync();
var testEvent = JsonSerializer.Deserialize<TestEvent>(body);
But cannot get the serialization to work any other way and I'd rather not have to manually deserialize all of my POSTs. Is there any obvious reason this is not working?
And the deserialization works correctly when I run the API locally, so it has something to do with the AWS ApiGateway or the Lambda.