Reputation: 210
I am converting several .NET Core 6 web services to AWS Lambda functions. I have completed eight so far with no issues, except for this one. I am trying to test it from Visual Studio using the mock lambda tool. This is my mock json request:
{
"body": "{\"PolicyNumbers\":[{\"Number\":\"WCU9799P\"},{\"Number\":\"B1V48603\"}],\"RenewalEffectiveDate\":\"09/28/2016\",\"State\":\"\"}",
"resource": "/{proxy+}",
"path": "api/GetClaimsCount",
"httpMethod": "POST",
"headers": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate, sdch",
"Accept-Language": "en-US,en;q=0.8"
}
}
Before the debugger hits the first line of my function handler, I get a long error that begins with:
System.Exception: Error deserializing the input JSON to type String at Amazon.Lambda.TestTool.Runtime.LambdaExecutor.BuildParameters(ExecutionRequest request, ILambdaContext context) in ...
And here is the beginning of my function handler. I use this same code on the other lambdas and it works fine. I think this has something to do with the array part of this json. If I am right, then how do I format my request to accept json arrays?
public Task<APIGatewayHttpApiV2ProxyResponse> FunctionHandler(string input, ILambdaContext context)
{
string? message = "";
string inputString = (input != null) ? JsonSerializer.Serialize(input) :
string.Empty;
_log.Debug("Request:" + inputString);
Upvotes: 0
Views: 1033
Reputation: 210
I found the issue. I need to change the first parameter in the Function Handler to "ApiGatewayRequest.Root input" since the request is coming through the API Gateway:
public Task<APIGatewayHttpApiV2ProxyResponse> FunctionHandler(ApiGatewayRequest.Root input, ILambdaContext context)
{
string? message = "";
string inputString = (input != null) ? JsonSerializer.Serialize(input) :
string.Empty;
_log.Debug("Request:" + inputString);
Upvotes: 0
Reputation: 16970
It appears there is a closing brace missing
{
"body": "{\"PolicyNumbers\":[{\"Number\":\"WCU9799P\"},{\"Number\":\"B1V48603\"}],\"RenewalEffectiveDate\":\"09/28/2016\",\"State\":\"\"}",
"resource": "/{proxy+}",
"path": "api/GetClaimsCount",
"httpMethod": "POST",
"headers": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate, sdch",
"Accept-Language": "en-US,en;q=0.8"
.... does this next brace close "headers"
or the entire object"?
}
Try adding a final }
at the end and see if that helps.
Also tools like https://jsonformatter.curiousconcept.com/ could be quite handy in this situation to see if the JSON is valid.
Upvotes: 0